auth-yes/forum/poc-g1/dependency_graph_poc.ts
Tyler Gillispie 8f61cbdc49
feat(forum): add Generation 2 agent forum PoCs with production tools (#67)
- Renamed `forum/experiments` to `forum/poc-g1` to designate generation 1.
- Created `forum/poc-g2` and a new `lab.ts` runner.
- Non-destructively migrated `dag_engine_poc.ts`, `git_storage_poc.ts`, `merkle_diff_poc.ts`, and `frontmatter_poc.ts` to `poc-g2`.
- Upgraded migrated PoCs to utilize actual production-ready tools (e.g. `std/yaml` parsing and isolated `Deno.Command` Git repos) per blueprint constraints.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
Co-authored-by: mrteye <1945243+mrteye@users.noreply.github.com>
2026-08-28 21:10:21 -07:00

67 lines
2.1 KiB
TypeScript

import { assertEquals } from "https://deno.land/std@0.224.0/testing/asserts.ts";
/**
* Proof of Concept: Dependency Graphing (Adjacency Matrices)
*
* Demonstrates mathematically calculating the "blast radius" of a code change
* by representing component dependencies as an adjacency matrix and using
* graph traversal to find impacted nodes.
*/
// Adjacency matrix for a simple app:
// Nodes: [0: Auth, 1: Database, 2: API Route, 3: UI Component]
// Matrix[i][j] = 1 means Node i depends on Node j
const matrix = [
[0, 1, 0, 0], // Auth depends on Database
[0, 0, 0, 0], // Database has no outgoing dependencies
[1, 1, 0, 0], // API Route depends on Auth and Database
[0, 0, 1, 0], // UI Component depends on API Route
];
const nodes = ["Auth", "Database", "API Route", "UI Component"];
// Find all nodes that depend on a given node (blast radius)
function calculateBlastRadius(changedNodeIndex: number): number[] {
const impacted = new Set<number>();
const queue = [changedNodeIndex];
while (queue.length > 0) {
const current = queue.shift()!;
// Find who depends on `current`
for (let i = 0; i < matrix.length; i++) {
if (matrix[i][current] === 1 && !impacted.has(i)) {
impacted.add(i);
queue.push(i);
}
}
}
return Array.from(impacted);
}
if (import.meta.main) {
console.log("Running Dependency Graphing PoC tests...");
try {
const changedNode = 1; // "Database" changed
console.log(
`If '${nodes[changedNode]}' changes, calculating blast radius...`,
);
const impactedIndices = calculateBlastRadius(changedNode);
const impactedNames = impactedIndices.map((i) => nodes[i]);
console.log(`Impacted components:`, impactedNames);
// If Database changes, Auth and API Route depend on it directly.
// UI Component depends on API Route. So all others should be impacted.
assertEquals(impactedIndices.length, 3);
console.log(
"✅ Dependency Graphing PoC successful: Blast radius calculated correctly.",
);
} catch (err) {
console.error("❌ Dependency Graphing PoC failed:", err);
Deno.exit(1);
}
}