fix(sdk): forward --ws workstream flag through query dispatch (#2546)
* fix(sdk): forward --ws workstream flag through query dispatch (closes #2524) - cli.ts: pass args.ws as workstream to registry.dispatch() - registry.ts: add workstream? param to dispatch(), thread to handler - utils.ts: add optional workstream? to QueryHandler type signature - helpers.ts: planningPaths() accepts workstream? and uses relPlanningPath() - All ~26 query handlers updated to receive and pass workstream to planningPaths() - Config/commit/intel handlers use _workstream (project-global, not scoped) - Add failing-then-passing test: tests/bug-2524-sdk-query-ws-flag.test.cjs Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix(sdk): forward workstream to all downstream query helpers Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix(test): rewrite #2524 test as static source assertions — no sdk/dist build in CI Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
107
tests/bug-2524-sdk-query-ws-flag.test.cjs
Normal file
107
tests/bug-2524-sdk-query-ws-flag.test.cjs
Normal file
@@ -0,0 +1,107 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Bug #2524: gsd-sdk query --ws <name> silently ignores the workstream flag.
|
||||
* Tests that --ws is forwarded through the call chain:
|
||||
* cli.ts -> registry.dispatch() -> planningPaths()
|
||||
*
|
||||
* Uses static source-file text assertions (no sdk/dist/ build required in CI).
|
||||
*/
|
||||
|
||||
const { test, describe } = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
|
||||
const helpersTs = fs.readFileSync(
|
||||
path.join(__dirname, '../sdk/src/query/helpers.ts'),
|
||||
'utf-8',
|
||||
);
|
||||
const registryTs = fs.readFileSync(
|
||||
path.join(__dirname, '../sdk/src/query/registry.ts'),
|
||||
'utf-8',
|
||||
);
|
||||
const cliTs = fs.readFileSync(
|
||||
path.join(__dirname, '../sdk/src/cli.ts'),
|
||||
'utf-8',
|
||||
);
|
||||
|
||||
// ─── Layer 3: planningPaths() accepts workstream ───────────────────────────
|
||||
|
||||
describe('planningPaths() workstream support', () => {
|
||||
test('planningPaths signature includes optional workstream parameter', () => {
|
||||
assert.ok(
|
||||
helpersTs.includes('planningPaths(projectDir: string, workstream?: string)'),
|
||||
'planningPaths must accept an optional workstream parameter',
|
||||
);
|
||||
});
|
||||
|
||||
test('planningPaths uses relPlanningPath(workstream) to compute the base path', () => {
|
||||
assert.ok(
|
||||
helpersTs.includes('relPlanningPath(workstream)'),
|
||||
'planningPaths must call relPlanningPath(workstream) to scope the base path',
|
||||
);
|
||||
});
|
||||
|
||||
test('planningPaths imports relPlanningPath from workstream-utils', () => {
|
||||
assert.ok(
|
||||
helpersTs.includes('relPlanningPath'),
|
||||
'helpers.ts must import/use relPlanningPath from workstream-utils',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
// ─── Layer 2: QueryRegistry.dispatch() accepts workstream ─────────────────
|
||||
|
||||
describe('QueryRegistry.dispatch() workstream threading', () => {
|
||||
test('dispatch method signature includes workstream parameter', () => {
|
||||
assert.ok(
|
||||
registryTs.includes('workstream?: string'),
|
||||
'dispatch() must accept an optional workstream parameter',
|
||||
);
|
||||
});
|
||||
|
||||
test('dispatch forwards workstream to the handler as third argument', () => {
|
||||
assert.ok(
|
||||
registryTs.includes('handler(args, projectDir, workstream)'),
|
||||
'dispatch() must pass workstream as the third argument to the handler',
|
||||
);
|
||||
});
|
||||
|
||||
test('QueryHandler type accepts a third workstream argument', () => {
|
||||
// QueryHandler type is defined in utils.ts, but registry.ts imports and uses it
|
||||
const utilsTs = fs.readFileSync(
|
||||
path.join(__dirname, '../sdk/src/query/utils.ts'),
|
||||
'utf-8',
|
||||
);
|
||||
assert.ok(
|
||||
utilsTs.includes('workstream?: string') && utilsTs.includes('QueryHandler'),
|
||||
'QueryHandler type must include an optional workstream parameter',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
// ─── Layer 1: CLI forwards args.ws to registry.dispatch() ─────────────────
|
||||
|
||||
describe('CLI forwards --ws to registry.dispatch()', () => {
|
||||
test('cli.ts passes args.ws as the workstream argument to registry.dispatch()', () => {
|
||||
assert.ok(
|
||||
cliTs.includes('registry.dispatch(matched.cmd, matched.args, args.projectDir, args.ws)'),
|
||||
'cli.ts must forward args.ws to registry.dispatch() as the workstream argument',
|
||||
);
|
||||
});
|
||||
|
||||
test('cli.ts defines a ws field in ParsedCliArgs', () => {
|
||||
assert.ok(
|
||||
cliTs.includes('ws: string | undefined'),
|
||||
'ParsedCliArgs must have a ws field typed as string | undefined',
|
||||
);
|
||||
});
|
||||
|
||||
test('cli.ts parses --ws flag from query argv', () => {
|
||||
assert.ok(
|
||||
cliTs.includes("if (a === '--ws' && argv[i + 1])"),
|
||||
'cli.ts query permissive parser must handle the --ws flag',
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user