Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/core/src/cli/handlers/graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,10 @@ async function runComponentGraphView(
id: name,
kind: "Component",
lexicon: "chant",
attrs: { wave: waveOf.get(name) ?? null },
// `liveNames` (#1491): the resources this component owns — declared, or
// the contract's `[name]` identity fallback — so a consumer can join
// the component DAG to the resource graph instead of guessing at kinds.
attrs: { wave: waveOf.get(name) ?? null, liveNames: graph.liveNames?.[name] ?? [name] },
// Deep-link the node to its `*.component.ts` (behold's inspect panel).
...(graph.files?.[name] ? { sourceLoc: { file: graph.files[name] } } : {}),
})),
Expand Down
17 changes: 17 additions & 0 deletions packages/core/src/components/cli-support.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,23 @@ describe("computeComponentGraph", () => {
expect(result.success).toBe(false);
expect(result.error).toMatch(/unknown component|ghost/i);
});

test("carries each component's liveNames, with the [name] identity fallback (#1491)", async () => {
await writeFile(
join(testDir, "pg.component.ts"),
`export const pg = { name: "postgres", liveNames: ["pgDeployment", "pgService", "pgClaim"], dependsOn: [], deploy: [{ phase: "Apply", steps: [{ kind: "shell", reason: "test" }] }] };`,
);
await writeFile(
join(testDir, "plain.component.ts"),
`export const plain = { name: "plain", dependsOn: [], deploy: [{ phase: "Apply", steps: [{ kind: "shell", reason: "test" }] }] };`,
);

const result = await computeComponentGraph(testDir);

expect(result.success).toBe(true);
expect(result.liveNames?.postgres).toEqual(["pgDeployment", "pgService", "pgClaim"]);
expect(result.liveNames?.plain).toEqual(["plain"]);
});
});

// ── runComponents (#585) ─────────────────────────────────────────────────────
Expand Down
12 changes: 11 additions & 1 deletion packages/core/src/components/cli-support.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ export interface ComponentGraphResult {
* so a renderer can deep-link a component node to source (`chant graph
* --components --format ir` sets `sourceLoc` from this). */
files?: Record<string, string>;
/** Component name → the live resource names it owns (#1491): the declared
* `liveNames`, or `[name]` when undeclared — the identity-join fallback the
* `Component` contract already specifies. This is what lets a consumer join
* the component DAG to the resource graph without guessing at kinds. */
liveNames?: Record<string, string[]>;
error?: string;
}

Expand All @@ -154,8 +159,13 @@ export async function computeComponentGraph(path: string, sandbox?: boolean): Pr

// component name → its declaring file, relative to `path`, for node deep-links.
const files: Record<string, string> = {};
// component name → owned live resource names (#1491), declared or the
// contract's identity fallback.
const liveNames: Record<string, string[]> = {};
for (const [name, discovered] of result.components) {
files[name] = relative(path, discovered.filePath);
const declared = discovered.component.liveNames;
liveNames[name] = declared && declared.length > 0 ? [...declared] : [name];
}

try {
Expand All @@ -164,7 +174,7 @@ export async function computeComponentGraph(path: string, sandbox?: boolean): Pr
for (const c of driverComponents) {
for (const dep of c.dependsOn ?? []) edges.push({ from: c.name, to: dep });
}
return { success: true, order, waves, edges, files };
return { success: true, order, waves, edges, files, liveNames };
} catch (err) {
if (err instanceof UnknownDependencyError || err instanceof DependencyCycleError) {
return { success: false, order: [], waves: [], edges: [], error: err.message };
Expand Down