Files
msd-core/tests/fix-2598-opencode-background-dispatch.test.cjs
sim 7dd9e59f6b test(#3090): stop exempting violations under categories that do not fit
An allow-test-rule annotation citing a category that does not apply is worse
than no annotation, because it reads as reviewed. Eight were confirmed by
reading the assertions each one covered, and auditing the rest found five more
plus one refutation — a converter test whose wording described the wrong
mechanism while the covered assertion genuinely was deployed-text.

The instructive one used the CANONICAL string for the same mistake: STATE.md
command output labelled as a deployed artifact. A canonical string is not
evidence the category fits, which is why normalising strings alone would have
laundered the problem rather than fixed it. Every mapping the audit had inferred
rather than code-verified was spot-checked before rewriting, and the ones that
turned out not to fit were re-annotated rather than relabelled.

Fourteen STATE.md assertions had a typed extractor available all along and now
use it; their annotations came out because nothing needs exempting. Eight
assertions genuinely need a production change first — CLI stdout and stderr with
no structured mode — and are tagged pending-migration-to-typed-ir citing #3090,
which is what that category is for. It had zero real uses before this, while one
file carried a real citation to migration issue #2974 under a non-canonical tag.

Six annotations covered assertions that do no text matching at all. An exemption
for a violation that does not exist is noise that makes the real ones harder to
audit; those are removed.

atomic-write-coverage gains the annotation it always warranted — its own
docstring describes a structural-regression-guard while the file carried none.

Fifty-nine non-canonical strings across roughly thirty files are normalised, and
the allow-test-rule allowlist is regenerated to match. 472 annotations became
463: every one now uses a canonical category, and the two remaining
non-canonical strings are ESLint RuleTester fixtures, not annotations.

Refs #3057

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-05 17:20:56 -04:00

92 lines
4.1 KiB
JavaScript

/**
* #2598 — the OpenCode descriptor declared background/concurrent subagent
* dispatch that OpenCode does not actually provide by default.
*
* `capabilities/opencode/capability.json` carried
* `runtime.hostIntegration.dispatch.background: true` and
* `dispatch.backgroundDispatch: true`. OpenCode's native subagent dispatch
* (Task tool / `@`-mention / `subtask`) is synchronous: the `background`
* parameter is hidden from the model behind the opt-in
* `OPENCODE_EXPERIMENTAL_BACKGROUND_SUBAGENTS` flag, which defaults to false
* (`enabledByExperimental(...)` over a `bool()` that defaults false), and the
* session loop still `tasks.pop()`s one subtask at a time (upstream #14195,
* #29638 — the latter still open).
*
* `negotiateHostCapabilities` and every `degradationFor`/`shouldFlattenDispatch`
* consumer TRUSTS these per-field values, so declaring a capability the host
* lacks overstates it — the opposite of the fail-closed posture the negotiation
* exists to enforce.
*
* History note: these fields were flipped to `true` by #2087 citing a reading of
* OpenCode v1.17 as "background subagents enabled by default in all modes".
* That reading does not hold against current upstream `dev`, where the flag is
* opt-in. This test pins the corrected values so a future descriptor edit cannot
* silently re-assert an unsupported capability.
*/
// allow-test-rule: source-text-is-the-product #2598 — the descriptor JSON and the
// host-integration matrix ARE the negotiated contract; asserting their values is behavioral.
'use strict';
process.env.GSD_TEST_MODE = '1';
const { test, describe } = require('node:test');
const assert = require('node:assert/strict');
const fs = require('node:fs');
const path = require('node:path');
const ROOT = path.join(__dirname, '..');
const DESCRIPTOR = path.join(ROOT, 'capabilities', 'opencode', 'capability.json');
const MATRIX = path.join(ROOT, 'docs', 'reference', 'host-integration-capability-matrix.md');
function opencodeDispatch() {
const parsed = JSON.parse(fs.readFileSync(DESCRIPTOR, 'utf8'));
return parsed.runtime.hostIntegration.dispatch;
}
describe('#2598: OpenCode does not declare background/concurrent subagent dispatch', () => {
test('descriptor declares background: false', () => {
assert.equal(
opencodeDispatch().background,
false,
'OpenCode subagent dispatch is synchronous unless an experimental opt-in flag is set',
);
});
test('descriptor declares backgroundDispatch: false', () => {
assert.equal(
opencodeDispatch().backgroundDispatch,
false,
'concurrent dispatch requires an opt-in flag, so it must not be declared as available',
);
});
test('the capabilities that ARE real are left intact', () => {
// Narrow the blast radius: this fix must not quietly downgrade neighbouring
// sub-fields that were never in question.
const d = opencodeDispatch();
assert.equal(d.namedDispatch, true, 'named subagent dispatch is genuinely supported');
assert.equal(d.subagentToolkit, 'full', 'the general subagent has full tool access');
assert.equal(d.isolation, 'orchestrator-worktree',
'isolation is orchestrator-managed via `opencode run --dir`, unaffected by #2598');
});
test('the host-integration matrix agrees with the descriptor', () => {
// ADR-1239 designates the matrix the deployment source-of-truth; a
// descriptor/matrix disagreement is how this defect survived in the first
// place (the matrix said true, the ADR binding table said false).
const matrix = fs.readFileSync(MATRIX, 'utf8');
const section = matrix.slice(matrix.indexOf('## opencode'));
const end = section.indexOf('\n## ');
const opencodeSection = end === -1 ? section : section.slice(0, end);
for (const field of ['dispatch.background', 'dispatch.backgroundDispatch']) {
const row = opencodeSection.split('\n').find((l) => l.startsWith(`| ${field} |`));
assert.ok(row, `matrix must document ${field} for opencode`);
const value = row.split('|')[2].trim();
assert.equal(value, 'false', `matrix ${field} must match the descriptor`);
}
});
});