refactor(graph): the missing-dependency note is a string, not a callback

topoSort, finalizeGraph, assertNeedsSatisfiable and finalize all threaded a
`(key: string) => string`, and no caller ever read `key` — the one producer,
in prepareGraph, is `() => ...`. The note names which teapots did not connect,
which does not vary by token, so the parameter was machinery for a
customization nothing asked for.

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
This commit is contained in:
chrnx committed 2026-09-12 15:40:25 -05:00
1 parent bff8778112
commit 727987286b
2 files changed
+7 -7

No files matched your search

+5 -5
View File
@@ -221,7 +221,7 @@ export function createApp(opts: {
let remoteRoutes: RouteDef[] = []; let remoteRoutes: RouteDef[] = [];
const meshLinks: Link[] = []; const meshLinks: Link[] = [];
const finalize = (missingNote?: (key: string) => string): void => { const finalize = (missingNote?: string): void => {
({ orderedProviders, orderedSteps } = finalizeGraph(registry, logger, opts.warnGraphDepth, missingNote)); ({ orderedProviders, orderedSteps } = finalizeGraph(registry, logger, opts.warnGraphDepth, missingNote));
booted = true; booted = true;
}; };
@@ -244,7 +244,7 @@ export function createApp(opts: {
// Without this the error is `missing dependency: auth needed by getUser` and says nothing // Without this the error is `missing dependency: auth needed by getUser` and says nothing
// about the teapot that was away — which is the actual cause every time it is the cause. // about the teapot that was away — which is the actual cause every time it is the cause.
const meshNote = spliced.absent.length const meshNote = spliced.absent.length
? () => ` — these teapots did not connect, so their exports are absent: ${spliced.absent.join(', ')}` ? ` — these teapots did not connect, so their exports are absent: ${spliced.absent.join(', ')}`
: undefined; : undefined;
finalize(meshNote); finalize(meshNote);
} }
@@ -667,7 +667,7 @@ function finalizeGraph(
registry: Registry, registry: Registry,
logger: Logger, logger: Logger,
warnDepth: number | false = DEEP_GRAPH_WARN, warnDepth: number | false = DEEP_GRAPH_WARN,
missingNote?: (key: string) => string, missingNote?: string,
): { orderedProviders: GraphNode[]; orderedSteps: GraphNode[] } { ): { orderedProviders: GraphNode[]; orderedSteps: GraphNode[] } {
const { providerNodes, stepNodes, routePlans } = registry; const { providerNodes, stepNodes, routePlans } = registry;
const ordered = topoSort([...providerNodes, ...stepNodes], ['req', 'params'], missingNote); const ordered = topoSort([...providerNodes, ...stepNodes], ['req', 'params'], missingNote);
@@ -711,7 +711,7 @@ function assertNeedsSatisfiable(
routePlans: RoutePlan[], routePlans: RoutePlan[],
providerNodes: GraphNode[], providerNodes: GraphNode[],
stepNodes: GraphNode[], stepNodes: GraphNode[],
missingNote?: (key: string) => string, missingNote?: string,
): void { ): void {
const producedKeys = new Set<string>([ const producedKeys = new Set<string>([
...providerNodes.flatMap((node) => node.provides), ...providerNodes.flatMap((node) => node.provides),
@@ -744,7 +744,7 @@ function assertNeedsSatisfiable(
const scope = missingNote ? 'local or connected mesh' : 'local or mesh'; const scope = missingNote ? 'local or connected mesh' : 'local or mesh';
throw new Error( throw new Error(
`handler '${plan.handlerName}' needs '${need}' but nothing (${scope}) provides it` + `handler '${plan.handlerName}' needs '${need}' but nothing (${scope}) provides it` +
`${hint ? ` — did you mean '${hint}'?` : ''}${missingNote?.(need) ?? ''}`, `${hint ? ` — did you mean '${hint}'?` : ''}${missingNote ?? ''}`,
); );
} }
} }
+2 -2
View File
@@ -43,7 +43,7 @@ export interface GraphNode {
} }
/** Orders nodes so every dependency precedes its dependents; throws on missing keys or cycles. */ /** Orders nodes so every dependency precedes its dependents; throws on missing keys or cycles. */
export function topoSort(nodes: GraphNode[], seedKeys: string[], note?: (key: string) => string): GraphNode[] { export function topoSort(nodes: GraphNode[], seedKeys: string[], note = ''): GraphNode[] {
const producedBy = new Map<string, GraphNode>(); const producedBy = new Map<string, GraphNode>();
for (const node of nodes) for (const key of node.provides) producedBy.set(key, node); for (const node of nodes) for (const key of node.provides) producedBy.set(key, node);
@@ -51,7 +51,7 @@ export function topoSort(nodes: GraphNode[], seedKeys: string[], note?: (key: st
for (const node of nodes) { for (const node of nodes) {
for (const key of node.needs) { for (const key of node.needs) {
if (!seedKeys.includes(key) && !producedBy.has(key)) { if (!seedKeys.includes(key) && !producedBy.has(key)) {
throw new Error(`missing dependency: ${key} needed by ${node.name}${note?.(key) ?? ''}`); throw new Error(`missing dependency: ${key} needed by ${node.name}${note}`);
} }
} }
} }