Files
msd-core/tests/resolution.test.cjs
Tom Boucher b0c774c2e3 feat(#1416): formalize Resolution convention + agent-skills value envelope (Resolution Provenance P3) (#1425)
Narrows P3 of ADR-1411 (Resolution Provenance, epic #1411) based on an
adversarial fit-analysis that showed a single Resolution<T> envelope adopted
by agent-skills, capability-state, and capability-writer fails the deletion
test: configured/reason are meaningless for capability verbs, and
capability-writer's errors[] (operation-not-applied) cannot fold into
warnings[]. The only genuinely shared seam is warnings: string[].

Changes:

- src/resolution.cts: new pure types+builder leaf — exports Resolution<T>
  {value, configured, reason, warnings}, makeResolution<T>() builder, and
  AgentSkillsValue {block, skills_count}. No other src/ imports.

- src/init.cts: cmdAgentSkills --json IR gains additive value:{block,
  skills_count} field (built via makeResolution). All existing flat fields
  (agent_type, block, skills_count, warnings, configured, reason, source,
  degraded) are retained unchanged for back-compat.

- src/capability-state.cts: doc comment on ResolveCapabilityRuntimeStateResult
  naming it the canonical read-verb envelope. No JSON change.

- src/capability-writer.cts: doc comment on SetCapabilityStateResult naming it
  the canonical mutation-verb result (warnings=advisory, errors=operation-
  not-applied). No JSON change.

- CONTEXT.md: new ### Resolution Convention glossary entry after
  ### Resolution Provenance.

- docs/adr/1411-resolution-provenance.md: P3 narrowing amendment appended.

- tests/resolution.test.cjs: 9 unit tests for makeResolution (new).
- tests/agent-skills.test.cjs: 2 P3 tests for value.block/value.skills_count
  and back-compat of all flat fields.

All 277 tests pass (5 suites). npm run lint clean. All lint checks pass.

Part of #1411

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-18 07:44:52 -04:00

90 lines
4.4 KiB
JavaScript

/**
* Unit tests for src/resolution.cts → gsd-core/bin/lib/resolution.cjs
*
* Tests the `makeResolution` builder and the `Resolution<T>` envelope shape
* introduced for ADR-1411 P3 (Resolution Provenance, #1416).
*/
'use strict';
const { test, describe } = require('node:test');
const assert = require('node:assert/strict');
const path = require('path');
const RESOLUTION_PATH = path.join(__dirname, '../gsd-core/bin/lib/resolution.cjs');
describe('resolution module — makeResolution builder', () => {
test('module loads and exports makeResolution', () => {
const mod = require(RESOLUTION_PATH);
assert.ok(mod, 'module must be truthy');
assert.strictEqual(typeof mod.makeResolution, 'function', 'makeResolution must be a function');
});
test('makeResolution builds the Resolution<T> shape', () => {
const { makeResolution } = require(RESOLUTION_PATH);
const result = makeResolution(
{ block: '<agent_skills />', skills_count: 1 },
{ configured: true, reason: 'resolved', warnings: [] },
);
assert.ok(result, 'result must be truthy');
assert.ok('value' in result, 'result must have value field');
assert.ok('configured' in result, 'result must have configured field');
assert.ok('reason' in result, 'result must have reason field');
assert.ok('warnings' in result, 'result must have warnings field');
});
test('makeResolution preserves the value as-is', () => {
const { makeResolution } = require(RESOLUTION_PATH);
const value = { block: '<agent_skills>test</agent_skills>', skills_count: 2 };
const result = makeResolution(value, { configured: true, reason: 'resolved', warnings: [] });
assert.deepStrictEqual(result.value, value, 'value must be preserved');
assert.strictEqual(result.value.block, '<agent_skills>test</agent_skills>');
assert.strictEqual(result.value.skills_count, 2);
});
test('makeResolution carries configured field', () => {
const { makeResolution } = require(RESOLUTION_PATH);
const trueResult = makeResolution({ block: '', skills_count: 0 }, { configured: true, reason: 'configured_empty', warnings: [] });
const falseResult = makeResolution({ block: '', skills_count: 0 }, { configured: false, reason: 'not_configured', warnings: [] });
assert.strictEqual(trueResult.configured, true, 'configured:true must be preserved');
assert.strictEqual(falseResult.configured, false, 'configured:false must be preserved');
});
test('makeResolution carries reason field', () => {
const { makeResolution } = require(RESOLUTION_PATH);
const reasons = ['resolved', 'not_configured', 'configured_empty', 'configured_unresolved'];
for (const reason of reasons) {
const result = makeResolution({ block: '', skills_count: 0 }, { configured: false, reason, warnings: [] });
assert.strictEqual(result.reason, reason, `reason '${reason}' must be preserved`);
}
});
test('makeResolution carries warnings array', () => {
const { makeResolution } = require(RESOLUTION_PATH);
const warnings = ['path /foo/bar not found', 'path /baz not found'];
const result = makeResolution({ block: '', skills_count: 0 }, { configured: true, reason: 'configured_unresolved', warnings });
assert.deepStrictEqual(result.warnings, warnings, 'warnings must be preserved');
assert.strictEqual(result.warnings.length, 2);
});
test('makeResolution with empty warnings array', () => {
const { makeResolution } = require(RESOLUTION_PATH);
const result = makeResolution({ block: '<agent_skills />', skills_count: 1 }, { configured: true, reason: 'resolved', warnings: [] });
assert.deepStrictEqual(result.warnings, [], 'empty warnings array must be preserved');
});
test('makeResolution works with non-AgentSkillsValue generics (string)', () => {
const { makeResolution } = require(RESOLUTION_PATH);
const result = makeResolution('hello', { configured: true, reason: 'resolved', warnings: [] });
assert.strictEqual(result.value, 'hello', 'string value must be preserved');
assert.strictEqual(result.configured, true);
});
test('makeResolution result has exactly the four envelope fields plus value', () => {
const { makeResolution } = require(RESOLUTION_PATH);
const result = makeResolution(42, { configured: false, reason: 'not_configured', warnings: [] });
const keys = Object.keys(result).sort();
assert.deepStrictEqual(keys, ['configured', 'reason', 'value', 'warnings'], 'envelope must have exactly 4 fields');
});
});