Files
msd-core/tests/autonomous-interactive.test.cjs
Jakub Zych a9a7a328e6 refactor: hard-fork GSD -> MSD (Make Software Done)
Mechanical rename produced by scripts/msd-rename.cjs: gsd/Gsd/GSD -> msd/Msd/MSD
across contents and paths, upstream package/repo coordinates -> @golem15/msd-core
and golem15com/msd-core. Deep links into upstream history, sibling upstream
packages, the GSD-2 import feature, CHANGELOG.md and .changeset/ are kept as-is.

Hand edits on top: MSD block-letter banner and logos, LICENSE copyright line,
package/plugin identity, regenerated lockfile, install-tree fixtures, derived
registries and benchmark baseline; migration checksum baseline re-locked
(MSD keeps its own install state, so no install had applied the old sums);
sort-order and regex-escaped expectations in tests adjusted.
2026-10-06 01:47:40 +02:00

121 lines
5.5 KiB
JavaScript

// allow-test-rule: source-text-is-the-product
// Workflow .md / agent .md / command .md / reference .md files — their text
// IS what the runtime loads. Testing text content tests the deployed contract.
// Per CONTRIBUTING.md exception matrix.
/**
* MSD Tools Tests - autonomous --interactive flag
*
* Validates that the autonomous workflow and command definition
* correctly document and support the --interactive flag.
*
* Closes: #1413
*/
const { test, describe } = require('node:test');
const assert = require('node:assert/strict');
const fs = require('fs');
const path = require('path');
describe('autonomous --interactive flag (#1413)', () => {
const workflowPath = path.join(__dirname, '..', 'msd-core', 'workflows', 'autonomous.md');
const commandPath = path.join(__dirname, '..', 'commands', 'msd', 'autonomous.md');
test('command definition includes --interactive in argument-hint', () => {
const content = fs.readFileSync(commandPath, 'utf8');
assert.ok(content.includes('--interactive'), 'command should document --interactive flag');
assert.ok(content.includes('argument-hint:') && content.includes('--interactive'),
'argument-hint should include --interactive');
});
test('command definition describes interactive mode behavior', () => {
const content = fs.readFileSync(commandPath, 'utf8');
assert.ok(content.includes('discuss') && content.includes('inline'),
'command should describe discuss running inline');
assert.ok(content.includes('background'),
'command should mention background agents for plan+execute');
});
test('workflow parses --interactive flag', () => {
const content = fs.readFileSync(workflowPath, 'utf8');
assert.ok(content.includes("--interactive") && content.includes('INTERACTIVE'),
'workflow should parse --interactive into INTERACTIVE variable');
});
test('workflow uses discuss-phase skill in interactive mode', () => {
// Per #2697 the user-facing form is the hyphen invariant msd-discuss-phase;
// the colon form was retired and is enforced absent by bug-2543 tests.
//
// Don't `.includes()` against the full file — both tokens could appear in
// unrelated sections (e.g. INTERACTIVE="" initialization + a stray
// msd-discuss-phase mention in prose) and falsely pass. Instead, isolate
// the structural region that gates on INTERACTIVE and assert the Skill
// invocation lives inside it.
const content = fs.readFileSync(workflowPath, 'utf8');
const interactiveMarker = '**If `INTERACTIVE` is set:**';
const branchStart = content.indexOf(interactiveMarker);
assert.notStrictEqual(
branchStart, -1,
`workflow must define an explicit '${interactiveMarker}' branch`,
);
// Bound the branch by the next "**If `..." prose marker (the non-interactive
// sibling) or, failing that, the next `<step ...>`/`</step>` boundary.
const afterStart = branchStart + interactiveMarker.length;
const candidates = [
content.indexOf('**If `INTERACTIVE` is NOT set', afterStart),
content.indexOf('**If `', afterStart),
content.indexOf('</step>', afterStart),
content.indexOf('<step ', afterStart),
].filter((i) => i !== -1);
assert.ok(candidates.length > 0, 'INTERACTIVE branch must have a closing boundary');
const branchEnd = Math.min(...candidates);
const branch = content.slice(branchStart, branchEnd);
// The branch must invoke the hyphen-form Skill. Tolerate whitespace
// around `(`, `skill`, and `=` so harmless reformatting doesn't break this.
const skillCall = /Skill\(\s*skill\s*=\s*['"]msd-discuss-phase['"]/.test(branch);
assert.ok(
skillCall,
`INTERACTIVE branch must invoke Skill(skill="msd-discuss-phase"). Got branch:\n${branch}`,
);
});
test('workflow dispatches plan as background agent in interactive mode', () => {
const content = fs.readFileSync(workflowPath, 'utf8');
// Should have Agent() with run_in_background for plan
assert.ok(
content.includes('run_in_background') && content.includes('plan-phase'),
'workflow should dispatch plan-phase as background agent in interactive mode'
);
});
test('workflow dispatches execute as background agent in interactive mode', () => {
const content = fs.readFileSync(workflowPath, 'utf8');
assert.ok(
content.includes('run_in_background') && content.includes('execute-phase'),
'workflow should dispatch execute-phase as background agent in interactive mode'
);
});
test('workflow describes pipeline parallelism in interactive mode', () => {
const content = fs.readFileSync(workflowPath, 'utf8');
assert.ok(
content.includes('pipeline parallelism') || content.includes('Phase N+1'),
'workflow should describe overlapping discuss/execute between phases'
);
});
test('success criteria include --interactive requirements', () => {
const content = fs.readFileSync(workflowPath, 'utf8');
// eslint-disable-next-line local/no-unbounded-quantifier -- parses this repo's own workflow .md content, fixed-size author-controlled content
const criteriaMatch = content.match(/<success_criteria>([\s\S]*?)<\/success_criteria>/);
const criteria = criteriaMatch ? criteriaMatch[1] : '';
assert.ok(criteria.includes('--interactive'),
'success criteria should include --interactive requirements');
assert.ok(criteria.includes('discuss inline'),
'success criteria should mention discuss inline');
assert.ok(criteria.includes('background agents'),
'success criteria should mention background agents');
});
});