Files
houseplan-card/test/task-packet.test.mjs
T
Claude f0c8ae24ba infra: portable Windows gate, CI toolchain pins, task packet, deterministic wait, gate:small --smokes
Windows portability (the three red tests on the owner's machine at green CI):
- scripts/spawn-portable.mjs: isMainModule via pathToFileURL (the
  `file://${argv[1]}` form gives file:///C:/C:/... and the CLI stays silent);
  portableCommand — a shell only for npm/npx/.cmd, node and git run directly
  (spawn via shell dropped the quotes of `node -e "…"`). Applied to
  classify-changes, mutation-gate-report, review-doc-guard, check-inputs,
  merge-candidate, gate-small, rebase-on-dev.
- the rebase-on-dev test pins core.autocrlf=false / core.eol=lf through
  GIT_CONFIG_* for its temp repository instead of touching the user's git
  config; test/windows-portability.test.mjs forbids both anti-patterns.

Pins: scripts/toolchain-pins.mjs reads Node/Python from validate.yml, the HA
stack from tests_backend/requirements.txt, Playwright/Chromium from the
lockfile — no second dictionary; `npm run toolchain:check` compares the
machine; .nvmrc/.python-version are derived and tested equal;
scripts/wsl-setup.sh provisions WSL/Linux with those pins.

scripts/task-packet.mjs: one derived view of an issue (status, rights, owner
decisions, branch vs dev, Validate on the tip, previous verdict with recorded
tree, AC → evidence, unwitnessed). scripts/wait-verdict.mjs: polls labels,
pipeline comments and optionally Validate, prints only on state change, exit
0/3/4, writes nothing.

gate:small --smokes: after build the browser phase runs bundle-sync and then
the directly matched and registered smokes, two at a time; broad matches stay
with the reviewer. package.json changed, so the bundle is rebuilt here.

Issue: #496
User-Visible: no
2026-09-09 01:11:24 +03:00

92 lines
6.3 KiB
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import {
buildPacket, evidenceFor, extractAcceptanceCriteria, lastVerdict, ownerDecisions, renderPacket, rightsFor,
} from '../scripts/task-packet.mjs';
import { materialAnchorBlock } from '../scripts/review-doc-guard.mjs';
// #496: пакет задачи — производное представление; проверяется, что он выводится
// из меток/комментариев/документов детерминированно и ничего не додумывает.
const TREE = 'a'.repeat(40);
test('права выводятся из статусной метки по правилу №1 (#496)', () => {
assert.ok(rightsFor('S6-in-progress').some((l) => l.includes('МОЖНО')));
assert.ok(rightsFor('S3-spec').some((l) => l.includes('НЕЛЬЗЯ')));
assert.ok(rightsFor('S7-code-review').some((l) => l.includes('#312')));
assert.ok(rightsFor('S6-in-progress', ['blocked'])[0].startsWith('blocked'));
assert.ok(rightsFor('S7-code-review', ['review-4'])[0].startsWith('review-4'));
assert.ok(rightsFor(null).some((l) => l.includes('вне процесса')));
});
test('AC распознаются из таблицы ТЗ и из строк тела issue (#496)', () => {
const table = '| # | AC | Чем краснеет |\n|---|---|---|\n| AC1 | initial View ≤ 290 000 Б | budget |\n| **AC2** | план с мебелью | смок |\n';
assert.deepEqual(extractAcceptanceCriteria(table).map((a) => a.id), ['AC1', 'AC2']);
const body = 'Текст\n- AC1: кнопка ОК видна\n- AC2 — Enter подтверждает\nAC1: дубликат игнорируется\n';
const acs = extractAcceptanceCriteria(body);
assert.deepEqual(acs.map((a) => a.id), ['AC1', 'AC2']);
assert.equal(acs[0].text, 'кнопка ОК видна');
});
test('свидетель AC берётся из последнего документа ревью; отсутствие — «без записи» (#496)', () => {
const acs = [{ id: 'AC1', text: 'x' }, { id: 'AC12', text: 'y' }, { id: 'AC2', text: 'z' }];
const doc = '## Разбор\nAC1 — доказан smoke_x, тест умеет падать\nAC12 проверен чтением\n';
const out = evidenceFor(acs, doc);
assert.match(out[0].evidence, /доказан smoke_x/);
assert.match(out[1].evidence, /проверен чтением/);
assert.equal(out[2].evidence, 'без записи в последнем документе ревью');
});
test('решения владельца — только его комментарии со словами решения (#496)', () => {
const comments = [
{ author: 'Matysh', body: '## Решения владельца и материалы\nтекст', createdAt: '2026-09-08T13:35:00Z', url: 'u1' },
{ author: 'claude[bot]', body: 'Вердикт: зелёный · решение не моё', createdAt: '2026-09-08T14:00:00Z' },
{ author: 'Matysh', body: 'Взял: автор ТЗ', createdAt: '2026-09-08T13:49:00Z' },
];
const out = ownerDecisions(comments, 'Matysh');
assert.equal(out.length, 1);
assert.equal(out[0].head, 'Решения владельца и материалы');
});
test('последний вердикт — из комментария и из записи конвейера в документе (#496)', () => {
const comments = [
{ body: 'Вердикт: жёлтый · заход r1 · High: 0 · Medium: 4 → в задаче', createdAt: '1' },
{ body: 'Вердикт: зелёный · заход r3 · High: 0 · Medium: 0', createdAt: '2' },
];
const docs = [
{ name: 'CODE-REVIEW-437-r1.md', text: materialAnchorBlock({ tree: 'b'.repeat(40), verdict: 'yellow', high: 0 }) },
{ name: 'CODE-REVIEW-437-r3.md', text: materialAnchorBlock({ tree: TREE, verdict: 'green', high: 0 }) },
{ name: 'SPEC-REVIEW-437-r2.md', text: materialAnchorBlock({ tree: 'c'.repeat(40), verdict: 'green', high: 0 }) },
];
const v = lastVerdict(comments, docs, 'code');
assert.match(v.comment.line, /зелёный · заход r3/);
assert.equal(v.doc.name, 'CODE-REVIEW-437-r3.md');
assert.equal(v.doc.tree, TREE);
assert.deepEqual(v.doc.recorded, { verdict: 'green', high: 0 });
assert.equal(lastVerdict(comments, docs, 'spec').doc.name, 'SPEC-REVIEW-437-r2.md');
});
test('пакет собирается и рендерится: статус, материал, совпадение дерева, непроверенное (#496)', () => {
const doc = `# CODE-REVIEW-437-r3\nAC1 — доказан smoke_x\n\n${materialAnchorBlock({ sha: 'd'.repeat(40), tree: TREE, branch: 'issue/437-summary-panel', verdict: 'green', high: 0 })}`;
const packet = buildPacket({
issue: { number: 437, title: 'View: панель', state: 'OPEN', url: 'https://x/437', body: '- AC1: панель видна\n- AC2: панель скрывается\n' },
labels: ['P2', 'feature', 'S6-in-progress', 'small'],
comments: [{ author: 'Matysh', body: '## Решения владельца\n…', createdAt: '2026-09-08T13:35:00Z' },
{ author: 'claude[bot]', body: 'Вердикт: зелёный · заход r3 · High: 0 · Medium: 0', createdAt: '2026-09-08T17:37:00Z' }],
branch: { name: 'issue/437-summary-panel', tip: 'e'.repeat(40), base: 'f'.repeat(40), ahead: 3, behind: 0, treeWithoutReviews: TREE },
reviewDocs: [{ name: 'CODE-REVIEW-437-r3.md', text: doc }],
validate: { status: 'зелёный', url: 'https://run' },
});
assert.equal(packet.status, 'S6-in-progress');
assert.equal(packet.track, 'small');
assert.equal(packet.material.treeMatchesVerdict, true);
assert.deepEqual(packet.unverified, ['AC2']);
const md = renderPacket(packet);
assert.match(md, /# Пакет задачи #437/);
assert.match(md, /применит его без модели \(#499\)/);
assert.match(md, /\*\*AC2\*\* панель скрывается → без записи/);
assert.match(md, /Validate на вершине: зелёный/);
// Ничего не додумывается: без ветки — прямо сказано, что материал не запушен.
assert.match(renderPacket(buildPacket({ issue: { number: 1, title: 't', state: 'OPEN', body: '' }, labels: [] })), /материал не запушен/);
});