arbiterdesign 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +151 -143
- package/dist/commands/candidate.js +1 -1
- package/dist/commands/export.js +58 -58
- package/dist/commands/init.js +67 -27
- package/dist/commands/publish.js +87 -2
- package/dist/commands/record.js +6 -1
- package/dist/commands/rules.js +4 -2
- package/dist/commands/update.js +114 -0
- package/dist/hosted.js +5 -0
- package/dist/index.js +26 -2
- package/dist/sweep.js +9 -2
- package/package.json +45 -44
- package/templates/SKILL.md +403 -393
- package/templates/review.html +479 -479
- package/dist/test/hosted.test.js +0 -189
- package/dist/test/init.test.js +0 -54
- package/dist/test/pending.test.js +0 -214
- package/dist/test/polish.test.js +0 -130
- package/dist/test/record.test.js +0 -102
- package/dist/test/stages.test.js +0 -188
package/dist/test/hosted.test.js
DELETED
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const node_test_1 = require("node:test");
|
|
7
|
-
const strict_1 = __importDefault(require("node:assert/strict"));
|
|
8
|
-
const node_fs_1 = __importDefault(require("node:fs"));
|
|
9
|
-
const node_os_1 = __importDefault(require("node:os"));
|
|
10
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
11
|
-
const node_http_1 = __importDefault(require("node:http"));
|
|
12
|
-
const candidate_1 = require("../commands/candidate");
|
|
13
|
-
const record_1 = require("../commands/record");
|
|
14
|
-
const publish_1 = require("../commands/publish");
|
|
15
|
-
const pull_1 = require("../commands/pull");
|
|
16
|
-
const snapshot_1 = require("../commands/snapshot");
|
|
17
|
-
const hosted_1 = require("../hosted");
|
|
18
|
-
const store_1 = require("../store");
|
|
19
|
-
const tmp = () => node_fs_1.default.mkdtempSync(node_path_1.default.join(node_os_1.default.tmpdir(), 'arbiter-hosted-'));
|
|
20
|
-
const write = (cwd, rel, data) => { node_fs_1.default.mkdirSync(node_path_1.default.join(cwd, node_path_1.default.dirname(rel)), { recursive: true }); node_fs_1.default.writeFileSync(node_path_1.default.join(cwd, rel), data); };
|
|
21
|
-
const PNG = Buffer.from('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==', 'base64');
|
|
22
|
-
/** A stand-in for hosted/: same three routes, same shapes, in memory. */
|
|
23
|
-
function fakeService() {
|
|
24
|
-
const state = { boards: {}, comments: [], tokens: {} };
|
|
25
|
-
return new Promise((resolve) => {
|
|
26
|
-
const server = node_http_1.default.createServer(async (req, res) => {
|
|
27
|
-
const body = await new Promise((r) => { let d = ''; req.on('data', (c) => (d += c)); req.on('end', () => r(d)); });
|
|
28
|
-
const send = (status, obj) => { res.writeHead(status, { 'content-type': 'application/json' }); res.end(JSON.stringify(obj)); };
|
|
29
|
-
const url = new URL(req.url, 'http://x');
|
|
30
|
-
const auth = req.headers.authorization?.replace('Bearer ', '');
|
|
31
|
-
if (req.method === 'POST' && url.pathname === '/api/projects') {
|
|
32
|
-
const id = 'p1';
|
|
33
|
-
state.tokens[id] = 'tok-secret';
|
|
34
|
-
return send(201, { id, slug: 'abc123', token: 'tok-secret', url: 'http://x/p/abc123' });
|
|
35
|
-
}
|
|
36
|
-
const m = /^\/api\/projects\/([^/]+)\/(board|comments|snapshots\/(?:C-\d+|W-[a-z0-9-]+))$/.exec(url.pathname);
|
|
37
|
-
if (!m)
|
|
38
|
-
return send(404, {});
|
|
39
|
-
if (state.tokens[m[1]] !== auth)
|
|
40
|
-
return send(401, { error: 'bad token' });
|
|
41
|
-
if (m[2].startsWith('snapshots/') && req.method === 'PUT') {
|
|
42
|
-
const type = req.headers['content-type'] ?? '';
|
|
43
|
-
if (!/^image\/(png|jpeg|webp|gif)$/.test(type))
|
|
44
|
-
return send(400, { error: 'type' });
|
|
45
|
-
if (!body.length)
|
|
46
|
-
return send(400, { error: 'empty' });
|
|
47
|
-
return send(200, { ok: true, url: `http://x/snap/${m[2].slice(10)}.png` });
|
|
48
|
-
}
|
|
49
|
-
if (m[2] === 'board' && req.method === 'PUT') {
|
|
50
|
-
const b = JSON.parse(body);
|
|
51
|
-
for (const c of b.candidates)
|
|
52
|
-
if (c.snapshot && typeof c.snapshot !== 'string')
|
|
53
|
-
return send(400, { error: 'bytes inline — upload through the snapshots route' });
|
|
54
|
-
state.boards[m[1]] = b;
|
|
55
|
-
return send(200, { ok: true, candidates: b.candidates.length, url: 'http://x/p/abc123' });
|
|
56
|
-
}
|
|
57
|
-
if (m[2] === 'comments' && req.method === 'GET') {
|
|
58
|
-
const since = url.searchParams.get('since');
|
|
59
|
-
const list = state.comments.filter((c) => !since || c.created_at > since);
|
|
60
|
-
return send(200, { comments: list, fetched_at: new Date().toISOString() });
|
|
61
|
-
}
|
|
62
|
-
send(405, {});
|
|
63
|
-
});
|
|
64
|
-
server.listen(0, '127.0.0.1', () => {
|
|
65
|
-
const { port } = server.address();
|
|
66
|
-
resolve({ url: `http://127.0.0.1:${port}`, state, close: () => server.close() });
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
(0, node_test_1.test)('publish --to creates the project once, uploads the board, pull merges comments', async () => {
|
|
71
|
-
const cwd = tmp();
|
|
72
|
-
const o = { cwd, author: 'test' };
|
|
73
|
-
write(cwd, 'shot.png', PNG);
|
|
74
|
-
write(cwd, 'shot.svg', '<svg xmlns="http://www.w3.org/2000/svg"/>');
|
|
75
|
-
(0, candidate_1.addCandidate)('Billing v2', { ...o, feature: 'billing', snapshot: 'shot.png' });
|
|
76
|
-
(0, candidate_1.addCandidate)('Billing v1', { ...o, feature: 'billing', snapshot: 'shot.svg' });
|
|
77
|
-
(0, record_1.record)(JSON.stringify({ change: 'Plan and card side by side', decision: 'Two half-width cards', rationale: 'r', trigger: 'Billing', scope: 'file:b.tsx', dimension: 'structure', class: 'judgment', verdict: 'accept', level: 'feature' }), { ...o, candidate: 'C-0001' });
|
|
78
|
-
(0, record_1.record)(JSON.stringify({ decision: 'h-9', rationale: 'r', trigger: 'Billing', scope: 'file:b.tsx', dimension: 'visual', class: 'mechanical', verdict: 'accept', level: 'polish' }), { ...o, candidate: 'C-0001' });
|
|
79
|
-
(0, candidate_1.updateCandidate)('C-0001', { ...o, state: 'approved', why: 'card was below the fold' });
|
|
80
|
-
// Ordinary work, no candidate: still reaches the board, as a card named for the piece of work — with a picture if one was attached.
|
|
81
|
-
(0, record_1.record)(JSON.stringify({ change: 'Filters apply as you pick them', decision: 'Report filters apply immediately', rationale: 'r', trigger: 'Reports filters', scope: 'pattern:filters', dimension: 'interaction', class: 'judgment', verdict: 'accept', level: 'pattern' }), o);
|
|
82
|
-
strict_1.default.equal((0, snapshot_1.snapshotWork)('reports filters', { cwd, file: 'shot.png' }).exitCode, 0, 'name matching is forgiving');
|
|
83
|
-
const svc = await fakeService();
|
|
84
|
-
try {
|
|
85
|
-
const { manifest, skipped } = (0, hosted_1.buildManifest)((0, store_1.resolvePaths)(cwd));
|
|
86
|
-
const cands = manifest.candidates;
|
|
87
|
-
strict_1.default.equal(cands[0].decisions.length, 1, 'polish left out');
|
|
88
|
-
const work = cands.find((c) => c.id === 'W-reports-filters');
|
|
89
|
-
strict_1.default.ok(work, 'screenless decision rides as a work card');
|
|
90
|
-
strict_1.default.ok(work.snapshot, 'its picture rides too');
|
|
91
|
-
strict_1.default.equal(work.name, 'Reports filters');
|
|
92
|
-
strict_1.default.equal(work.state, 'recorded');
|
|
93
|
-
strict_1.default.equal(work.work, true);
|
|
94
|
-
strict_1.default.equal(work.decisions.length, 1);
|
|
95
|
-
strict_1.default.ok(cands[0].snapshot, 'png included');
|
|
96
|
-
strict_1.default.equal(cands[1].snapshot, null, 'svg not uploaded');
|
|
97
|
-
strict_1.default.equal(skipped.length, 1);
|
|
98
|
-
const r1 = await (0, publish_1.publish)({ cwd, to: svc.url });
|
|
99
|
-
strict_1.default.ok(r1.ok, JSON.stringify(r1.steps));
|
|
100
|
-
strict_1.default.equal(r1.url, 'http://x/p/abc123');
|
|
101
|
-
strict_1.default.ok(r1.steps.some((s) => s.step === 'project' && s.outcome === 'done'));
|
|
102
|
-
const link = (0, hosted_1.readLink)((0, store_1.resolvePaths)(cwd));
|
|
103
|
-
strict_1.default.equal(link.token, undefined, 'no secret in the shareable file');
|
|
104
|
-
strict_1.default.equal((0, hosted_1.readToken)((0, store_1.resolvePaths)(cwd)), 'tok-secret');
|
|
105
|
-
const gi = node_fs_1.default.readFileSync(node_path_1.default.join(cwd, '.arbiter', '.gitignore'), 'utf8');
|
|
106
|
-
strict_1.default.ok(gi.includes('hosted.token') && !gi.includes('hosted.json'), 'token file ignored, link file shareable');
|
|
107
|
-
const r2 = await (0, publish_1.publish)({ cwd, to: svc.url });
|
|
108
|
-
strict_1.default.ok(!r2.steps.some((s) => s.step === 'project'), 'second publish reuses the project');
|
|
109
|
-
const board = svc.state.boards.p1;
|
|
110
|
-
strict_1.default.equal(board.candidates[0].state, 'approved');
|
|
111
|
-
strict_1.default.equal(board.candidates[0].snapshot, 'http://x/snap/C-0001.png', 'manifest carries the uploaded URL, not bytes');
|
|
112
|
-
strict_1.default.equal(board.candidates[1].snapshot, null);
|
|
113
|
-
strict_1.default.equal(board.candidates.find((c) => c.id === 'W-reports-filters').snapshot, 'http://x/snap/W-reports-filters.png');
|
|
114
|
-
// A PM says something.
|
|
115
|
-
svc.state.comments.push({ id: 'c1', candidate_id: 'C-0001', decision_id: null, kind: 'approve', author_name: 'Sam', author_email: 's@x', body: '', created_at: '2026-09-16T10:00:00.000Z' });
|
|
116
|
-
svc.state.comments.push({ id: 'c2', candidate_id: 'C-0001', decision_id: null, kind: 'comment', author_name: 'Sam', author_email: 's@x', body: 'Why not a sheet?', created_at: '2026-09-16T10:01:00.000Z' });
|
|
117
|
-
const out = await (0, pull_1.pull)({ cwd });
|
|
118
|
-
strict_1.default.ok(out.includes('✓ Sam — looks good'));
|
|
119
|
-
strict_1.default.ok(out.includes('Sam: Why not a sheet?'));
|
|
120
|
-
strict_1.default.equal((0, hosted_1.readComments)((0, store_1.resolvePaths)(cwd)).length, 2);
|
|
121
|
-
const again = await (0, pull_1.pull)({ cwd });
|
|
122
|
-
strict_1.default.ok(again.startsWith('Nothing new'));
|
|
123
|
-
strict_1.default.equal((0, hosted_1.readComments)((0, store_1.resolvePaths)(cwd)).length, 2, 'no duplicates');
|
|
124
|
-
}
|
|
125
|
-
finally {
|
|
126
|
-
svc.close();
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
(0, node_test_1.test)('publish --to fails cleanly when the service is down', async () => {
|
|
130
|
-
const cwd = tmp();
|
|
131
|
-
const r = await (0, publish_1.publish)({ cwd, to: 'http://127.0.0.1:1' });
|
|
132
|
-
strict_1.default.equal(r.ok, false);
|
|
133
|
-
strict_1.default.equal(r.steps[0].outcome, 'failed');
|
|
134
|
-
});
|
|
135
|
-
(0, node_test_1.test)('a teammate with hosted.json and ARBITER_PUBLISH_TOKEN updates the same project; without the token gets told what to do', async () => {
|
|
136
|
-
const cwd = tmp();
|
|
137
|
-
const o = { cwd, author: 'test' };
|
|
138
|
-
(0, candidate_1.addCandidate)('X', { ...o, feature: 'f' });
|
|
139
|
-
const svc = await fakeService();
|
|
140
|
-
try {
|
|
141
|
-
await (0, publish_1.publish)({ cwd, to: svc.url });
|
|
142
|
-
// Simulate a clone: link file present, token file absent.
|
|
143
|
-
node_fs_1.default.rmSync(node_path_1.default.join(cwd, '.arbiter', 'hosted.token'));
|
|
144
|
-
const r = await (0, publish_1.publish)({ cwd, to: svc.url });
|
|
145
|
-
strict_1.default.equal(r.ok, false);
|
|
146
|
-
strict_1.default.ok(r.steps[0].note.includes('ARBITER_PUBLISH_TOKEN'));
|
|
147
|
-
process.env.ARBITER_PUBLISH_TOKEN = 'tok-secret';
|
|
148
|
-
try {
|
|
149
|
-
const r2 = await (0, publish_1.publish)({ cwd, to: svc.url });
|
|
150
|
-
strict_1.default.ok(r2.ok, JSON.stringify(r2.steps));
|
|
151
|
-
strict_1.default.ok(!r2.steps.some((s) => s.step === 'project'), 'same project, not a second one');
|
|
152
|
-
}
|
|
153
|
-
finally {
|
|
154
|
-
delete process.env.ARBITER_PUBLISH_TOKEN;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
finally {
|
|
158
|
-
svc.close();
|
|
159
|
-
}
|
|
160
|
-
});
|
|
161
|
-
(0, node_test_1.test)('a site with an admin token refuses project creation without it, with a clear message', async () => {
|
|
162
|
-
const cwd = tmp();
|
|
163
|
-
(0, candidate_1.addCandidate)('X', { cwd, author: 'test', feature: 'f' });
|
|
164
|
-
const server = node_http_1.default.createServer((req, res) => {
|
|
165
|
-
req.resume();
|
|
166
|
-
if (req.method === 'PUT') {
|
|
167
|
-
res.writeHead(200, { 'content-type': 'application/json' });
|
|
168
|
-
return res.end('{"ok":true,"candidates":1,"url":"http://x/p/s"}');
|
|
169
|
-
}
|
|
170
|
-
if (req.headers['x-admin-token'] !== 'admin-1') {
|
|
171
|
-
res.writeHead(401, { 'content-type': 'application/json' });
|
|
172
|
-
return res.end('{"error":"admin token required"}');
|
|
173
|
-
}
|
|
174
|
-
res.writeHead(201, { 'content-type': 'application/json' });
|
|
175
|
-
res.end(JSON.stringify({ id: 'p', slug: 's', token: 't', url: 'http://x/p/s' }));
|
|
176
|
-
});
|
|
177
|
-
await new Promise((r) => server.listen(0, '127.0.0.1', () => r()));
|
|
178
|
-
const url = `http://127.0.0.1:${server.address().port}`;
|
|
179
|
-
try {
|
|
180
|
-
const r = await (0, publish_1.publish)({ cwd, to: url });
|
|
181
|
-
strict_1.default.equal(r.ok, false);
|
|
182
|
-
strict_1.default.ok(r.steps[0].note.includes('--admin-token'));
|
|
183
|
-
const r2 = await (0, publish_1.publish)({ cwd, to: url, admin: 'admin-1' });
|
|
184
|
-
strict_1.default.ok(r2.steps.some((s) => s.step === 'project' && s.outcome === 'done'));
|
|
185
|
-
}
|
|
186
|
-
finally {
|
|
187
|
-
server.close();
|
|
188
|
-
}
|
|
189
|
-
});
|
package/dist/test/init.test.js
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const node_test_1 = require("node:test");
|
|
7
|
-
const strict_1 = __importDefault(require("node:assert/strict"));
|
|
8
|
-
const node_fs_1 = __importDefault(require("node:fs"));
|
|
9
|
-
const node_os_1 = __importDefault(require("node:os"));
|
|
10
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
11
|
-
const init_1 = require("../commands/init");
|
|
12
|
-
const record_1 = require("../commands/record");
|
|
13
|
-
const store_1 = require("../store");
|
|
14
|
-
const tmp = () => node_fs_1.default.mkdtempSync(node_path_1.default.join(node_os_1.default.tmpdir(), 'arbiter-init-'));
|
|
15
|
-
(0, node_test_1.test)('init is idempotent and merges AGENTS.md', async () => {
|
|
16
|
-
const cwd = tmp();
|
|
17
|
-
node_fs_1.default.mkdirSync(node_path_1.default.join(cwd, '.claude'));
|
|
18
|
-
node_fs_1.default.writeFileSync(node_path_1.default.join(cwd, 'AGENTS.md'), '# Rules\n\nUse pnpm.\n');
|
|
19
|
-
const first = await (0, init_1.init)({ cwd, yes: true, skipInstall: true, author: 'test' });
|
|
20
|
-
strict_1.default.deepEqual(first.map((s) => [s.file, s.outcome]), [
|
|
21
|
-
['arbiter.json', 'created'],
|
|
22
|
-
['DECISIONS.md', 'created'],
|
|
23
|
-
['.arbiter/.gitignore', 'created'],
|
|
24
|
-
['.arbiter/archive.md', 'created'],
|
|
25
|
-
['.claude/skills/arbiter/SKILL.md', 'created'],
|
|
26
|
-
['AGENTS.md', 'updated'],
|
|
27
|
-
['CLAUDE.md', 'created'],
|
|
28
|
-
['package.json', 'skipped'],
|
|
29
|
-
]);
|
|
30
|
-
strict_1.default.equal((node_fs_1.default.readFileSync(node_path_1.default.join(cwd, 'CLAUDE.md'), 'utf8').match(/<!-- arbiter -->/g) ?? []).length, 1);
|
|
31
|
-
const agents = node_fs_1.default.readFileSync(node_path_1.default.join(cwd, 'AGENTS.md'), 'utf8');
|
|
32
|
-
strict_1.default.ok(agents.startsWith('# Rules\n\nUse pnpm.\n'), 'existing content kept');
|
|
33
|
-
strict_1.default.equal((agents.match(/<!-- arbiter -->/g) ?? []).length, 1);
|
|
34
|
-
// Record a rule between runs — a second init must not clobber it.
|
|
35
|
-
(0, record_1.record)(JSON.stringify({ decision: 'Keep me', rationale: 'r', trigger: 't', scope: 'global', dimension: 'content', class: 'judgment', verdict: 'rule' }), { cwd, author: 'test' });
|
|
36
|
-
const second = await (0, init_1.init)({ cwd, yes: true, skipInstall: true });
|
|
37
|
-
strict_1.default.ok(second.every((s) => s.outcome === 'unchanged' || s.outcome === 'skipped'), JSON.stringify(second));
|
|
38
|
-
strict_1.default.equal((node_fs_1.default.readFileSync(node_path_1.default.join(cwd, 'AGENTS.md'), 'utf8').match(/<!-- arbiter -->/g) ?? []).length, 1);
|
|
39
|
-
strict_1.default.equal((0, store_1.readActive)((0, store_1.resolvePaths)(cwd)).length, 1, 'DECISIONS.md not overwritten');
|
|
40
|
-
const config = JSON.parse(node_fs_1.default.readFileSync(node_path_1.default.join(cwd, 'arbiter.json'), 'utf8'));
|
|
41
|
-
strict_1.default.equal(config.destination, 'local');
|
|
42
|
-
strict_1.default.equal(config.author, 'test');
|
|
43
|
-
strict_1.default.equal(config.client, 'claude-code');
|
|
44
|
-
});
|
|
45
|
-
(0, node_test_1.test)('init writes a Cursor rule when told to', async () => {
|
|
46
|
-
const cwd = tmp();
|
|
47
|
-
await (0, init_1.init)({ cwd, yes: true, skipInstall: true, client: 'cursor', author: 'test' });
|
|
48
|
-
const mdc = node_fs_1.default.readFileSync(node_path_1.default.join(cwd, '.cursor', 'rules', 'arbiter.mdc'), 'utf8');
|
|
49
|
-
strict_1.default.ok(mdc.startsWith('---\ndescription: '));
|
|
50
|
-
strict_1.default.ok(mdc.includes('alwaysApply: false'));
|
|
51
|
-
strict_1.default.ok(mdc.includes('# Arbiter'));
|
|
52
|
-
strict_1.default.ok(node_fs_1.default.existsSync(node_path_1.default.join(cwd, '.cursor', 'commands', 'arbiter.md')));
|
|
53
|
-
strict_1.default.ok(!node_fs_1.default.existsSync(node_path_1.default.join(cwd, 'CLAUDE.md')), 'no CLAUDE.md for a Cursor project');
|
|
54
|
-
});
|
|
@@ -1,214 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const node_test_1 = require("node:test");
|
|
7
|
-
const strict_1 = __importDefault(require("node:assert/strict"));
|
|
8
|
-
const node_fs_1 = __importDefault(require("node:fs"));
|
|
9
|
-
const node_os_1 = __importDefault(require("node:os"));
|
|
10
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
11
|
-
const node_http_1 = __importDefault(require("node:http"));
|
|
12
|
-
const record_1 = require("../commands/record");
|
|
13
|
-
const rules_1 = require("../commands/rules");
|
|
14
|
-
const review_1 = require("../commands/review");
|
|
15
|
-
const setup_1 = require("../commands/setup");
|
|
16
|
-
const store_1 = require("../store");
|
|
17
|
-
const tmp = () => node_fs_1.default.mkdtempSync(node_path_1.default.join(node_os_1.default.tmpdir(), 'arbiter-pending-'));
|
|
18
|
-
const input = (over = {}) => JSON.stringify({
|
|
19
|
-
decision: 'Sheets put the primary action bottom-right',
|
|
20
|
-
rationale: 'Header actions collide with close on mobile.',
|
|
21
|
-
trigger: 'Settings build',
|
|
22
|
-
scope: 'pattern:sheet-actions',
|
|
23
|
-
dimension: 'interaction',
|
|
24
|
-
class: 'judgment',
|
|
25
|
-
verdict: 'rule',
|
|
26
|
-
...over,
|
|
27
|
-
});
|
|
28
|
-
(0, node_test_1.test)('queue writes to pending only; ids are P-', () => {
|
|
29
|
-
const cwd = tmp();
|
|
30
|
-
// The agent queues before anyone has judged — no verdict in the payload.
|
|
31
|
-
const r1 = (0, record_1.queue)(input({ verdict: undefined }), { cwd, author: 'test' });
|
|
32
|
-
const r2 = (0, record_1.queue)(input({ decision: 'Empty states are one line', scope: 'pattern:empty-state', dimension: 'states' }), { cwd, author: 'test' });
|
|
33
|
-
strict_1.default.equal(r1.output.id, 'P-0001');
|
|
34
|
-
strict_1.default.equal(r2.output.id, 'P-0002');
|
|
35
|
-
const p = (0, store_1.resolvePaths)(cwd);
|
|
36
|
-
strict_1.default.equal((0, store_1.readPending)(p).length, 2);
|
|
37
|
-
strict_1.default.equal((0, store_1.readArchive)(p).length, 0);
|
|
38
|
-
strict_1.default.equal((0, store_1.readActive)(p).length, 0);
|
|
39
|
-
strict_1.default.equal((0, store_1.readPending)(p)[0].verdict, 'pending');
|
|
40
|
-
});
|
|
41
|
-
(0, node_test_1.test)('judge: rule, accept, skip, fix', () => {
|
|
42
|
-
const cwd = tmp();
|
|
43
|
-
const o = { cwd, author: 'test' };
|
|
44
|
-
(0, record_1.queue)(input(), o);
|
|
45
|
-
(0, record_1.queue)(input({ decision: 'Two', scope: 'pattern:two' }), o);
|
|
46
|
-
(0, record_1.queue)(input({ decision: 'Three', scope: 'pattern:three' }), o);
|
|
47
|
-
(0, record_1.queue)(input({ decision: 'Four', scope: 'pattern:four' }), o);
|
|
48
|
-
const p = (0, store_1.resolvePaths)(cwd);
|
|
49
|
-
const r = (0, record_1.judge)('P-0001', { ...o, as: 'rule' });
|
|
50
|
-
strict_1.default.equal(r.exitCode, 0);
|
|
51
|
-
strict_1.default.equal(r.output.id, 'D-0001');
|
|
52
|
-
strict_1.default.equal(r.output.judged, 'P-0001');
|
|
53
|
-
strict_1.default.equal((0, store_1.readActive)(p).length, 1);
|
|
54
|
-
const a = (0, record_1.judge)('P-0002', { ...o, as: 'accept' });
|
|
55
|
-
strict_1.default.equal(a.output.verdict, 'accept');
|
|
56
|
-
strict_1.default.equal((0, store_1.readActive)(p).length, 1);
|
|
57
|
-
const s = (0, record_1.judge)('P-0003', { ...o, as: 'skip' });
|
|
58
|
-
strict_1.default.equal(s.output.status, 'skipped');
|
|
59
|
-
const f = (0, record_1.judge)('P-0004', { ...o, as: 'fix', to: 'Four, corrected' });
|
|
60
|
-
strict_1.default.equal(f.output.verdict, 'fix');
|
|
61
|
-
const fixed = (0, store_1.readArchive)(p).find((d) => d.id === f.output.id);
|
|
62
|
-
strict_1.default.equal(fixed.decision, 'Four, corrected');
|
|
63
|
-
strict_1.default.ok(fixed.rejected[0].startsWith('Four — corrected by test'));
|
|
64
|
-
strict_1.default.equal((0, store_1.readPending)(p).length, 0);
|
|
65
|
-
strict_1.default.equal((0, store_1.readArchive)(p).length, 3, 'skip is recorded nowhere');
|
|
66
|
-
});
|
|
67
|
-
(0, node_test_1.test)('judge as rule with overlap leaves it pending until answered', () => {
|
|
68
|
-
const cwd = tmp();
|
|
69
|
-
const o = { cwd, author: 'test' };
|
|
70
|
-
(0, record_1.record)(input(), o);
|
|
71
|
-
(0, record_1.queue)(input({ decision: 'Sheets put the primary action bottom-right and sticky' }), o);
|
|
72
|
-
const p = (0, store_1.resolvePaths)(cwd);
|
|
73
|
-
const r = (0, record_1.judge)('P-0001', { ...o, as: 'rule' });
|
|
74
|
-
strict_1.default.equal(r.exitCode, 2);
|
|
75
|
-
strict_1.default.equal((0, store_1.readPending)(p).length, 1, 'still pending');
|
|
76
|
-
const r2 = (0, record_1.judge)('P-0001', { ...o, as: 'rule', supersedes: 'D-0001' });
|
|
77
|
-
strict_1.default.equal(r2.exitCode, 0);
|
|
78
|
-
strict_1.default.equal((0, store_1.readPending)(p).length, 0);
|
|
79
|
-
strict_1.default.deepEqual((0, store_1.readActive)(p).map((d) => d.id), ['D-0002']);
|
|
80
|
-
});
|
|
81
|
-
(0, node_test_1.test)('judge rejects unknown or malformed ids and fix without --to', () => {
|
|
82
|
-
const cwd = tmp();
|
|
83
|
-
const o = { cwd, author: 'test' };
|
|
84
|
-
(0, record_1.queue)(input(), o);
|
|
85
|
-
strict_1.default.equal((0, record_1.judge)('P-0009', { ...o, as: 'rule' }).exitCode, 1);
|
|
86
|
-
strict_1.default.equal((0, record_1.judge)('D-0001', { ...o, as: 'rule' }).exitCode, 1);
|
|
87
|
-
strict_1.default.equal((0, record_1.judge)('P-0001', { ...o, as: 'fix' }).exitCode, 1);
|
|
88
|
-
strict_1.default.equal((0, store_1.readPending)((0, store_1.resolvePaths)(cwd)).length, 1);
|
|
89
|
-
});
|
|
90
|
-
(0, node_test_1.test)('review server: state, judge, done', async () => {
|
|
91
|
-
const cwd = tmp();
|
|
92
|
-
(0, record_1.queue)(input(), { cwd, author: 'test' });
|
|
93
|
-
const port = 47000 + Math.floor(Math.random() * 1000);
|
|
94
|
-
const done = (0, review_1.review)({ cwd, port, open: false });
|
|
95
|
-
await new Promise((r) => setTimeout(r, 200));
|
|
96
|
-
const state = await get(port, '/api/state');
|
|
97
|
-
strict_1.default.equal(state.pending.length, 1);
|
|
98
|
-
strict_1.default.equal(state.pending[0].id, 'P-0001');
|
|
99
|
-
const judged = await post(port, '/api/judge', { id: 'P-0001', as: 'rule' });
|
|
100
|
-
strict_1.default.equal(judged.exitCode, 0);
|
|
101
|
-
strict_1.default.equal(judged.id, 'D-0001');
|
|
102
|
-
strict_1.default.equal((await get(port, '/api/state')).pending.length, 0);
|
|
103
|
-
await post(port, '/api/done', {});
|
|
104
|
-
await done;
|
|
105
|
-
});
|
|
106
|
-
function get(port, p) {
|
|
107
|
-
return new Promise((resolve, reject) => {
|
|
108
|
-
node_http_1.default.get({ host: '127.0.0.1', port, path: p }, (res) => {
|
|
109
|
-
let d = '';
|
|
110
|
-
res.on('data', (c) => (d += c));
|
|
111
|
-
res.on('end', () => resolve(JSON.parse(d)));
|
|
112
|
-
}).on('error', reject);
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
function post(port, p, body) {
|
|
116
|
-
return new Promise((resolve, reject) => {
|
|
117
|
-
const req = node_http_1.default.request({ host: '127.0.0.1', port, path: p, method: 'POST', headers: { 'content-type': 'application/json' } }, (res) => {
|
|
118
|
-
let d = '';
|
|
119
|
-
res.on('data', (c) => (d += c));
|
|
120
|
-
res.on('end', () => resolve(JSON.parse(d)));
|
|
121
|
-
});
|
|
122
|
-
req.on('error', reject);
|
|
123
|
-
req.end(JSON.stringify(body));
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
(0, node_test_1.test)('judgeAll: --level polish confirms only polish; --trigger scopes to one piece of work', () => {
|
|
127
|
-
const cwd = tmp();
|
|
128
|
-
const o = { cwd, author: 'test' };
|
|
129
|
-
const q = (over) => (0, record_1.queue)(input({ verdict: undefined, ...over }), o);
|
|
130
|
-
q({ decision: 'Shell', level: 'feature', trigger: 'Settings build', scope: 'file:a.tsx' });
|
|
131
|
-
q({ decision: 'h-9', level: 'polish', trigger: 'Settings build', scope: 'file:a.tsx', change: 'Buttons match at h-9' });
|
|
132
|
-
q({ decision: 'chevron', level: 'polish', trigger: 'Audit page', scope: 'file:b.tsx', change: 'Dropped the chevron' });
|
|
133
|
-
q({ decision: 'Cards', level: 'pattern', trigger: 'Audit page', scope: 'pattern:cards' });
|
|
134
|
-
const p = (0, store_1.resolvePaths)(cwd);
|
|
135
|
-
const r = (0, record_1.judgeAll)({ ...o, as: 'accept', level: 'polish', trigger: 'Settings build' });
|
|
136
|
-
strict_1.default.equal(r.exitCode, 0);
|
|
137
|
-
strict_1.default.equal(r.output.judged.length, 1);
|
|
138
|
-
strict_1.default.deepEqual((0, store_1.readPending)(p).map((d) => d.decision), ['Shell', 'chevron', 'Cards']);
|
|
139
|
-
const r2 = (0, record_1.judgeAll)({ ...o, as: 'accept', level: 'polish' });
|
|
140
|
-
strict_1.default.deepEqual((0, store_1.readPending)(p).map((d) => d.decision), ['Shell', 'Cards']);
|
|
141
|
-
strict_1.default.equal(r2.output.pending, 2);
|
|
142
|
-
strict_1.default.equal((0, record_1.judgeAll)({ ...o, as: 'fix' }).exitCode, 1, 'fix is never bulk');
|
|
143
|
-
strict_1.default.equal((0, record_1.judgeAll)({ ...o, as: 'accept', level: 'polish' }).output.status, 'nothing-to-judge');
|
|
144
|
-
const r3 = (0, record_1.judgeAll)({ ...o, as: 'rule', level: 'pattern' });
|
|
145
|
-
strict_1.default.deepEqual(r3.output.judged, ['D-0003']);
|
|
146
|
-
strict_1.default.equal((0, store_1.readActive)(p).length, 1);
|
|
147
|
-
strict_1.default.deepEqual((0, store_1.readPending)(p).map((d) => d.decision), ['Shell']);
|
|
148
|
-
});
|
|
149
|
-
(0, node_test_1.test)('groupByTrigger keeps first-appearance order and splits polish', () => {
|
|
150
|
-
const cwd = tmp();
|
|
151
|
-
const o = { cwd, author: 'test' };
|
|
152
|
-
const q = (over) => (0, record_1.queue)(input({ verdict: undefined, ...over }), o);
|
|
153
|
-
q({ decision: 'b1', trigger: 'B', scope: 'pattern:b1' });
|
|
154
|
-
q({ decision: 'a1', trigger: 'A', scope: 'pattern:a1', level: 'polish' });
|
|
155
|
-
q({ decision: 'b2', trigger: 'B', scope: 'pattern:b2', level: 'polish' });
|
|
156
|
-
q({ decision: 'a2', trigger: 'A', scope: 'pattern:a2', level: 'feature' });
|
|
157
|
-
const groups = (0, rules_1.groupByTrigger)((0, store_1.readPending)((0, store_1.resolvePaths)(cwd)));
|
|
158
|
-
strict_1.default.deepEqual(groups.map((g) => g.trigger), ['B', 'A']);
|
|
159
|
-
strict_1.default.deepEqual(groups[0].items.map((d) => d.decision), ['b1']);
|
|
160
|
-
strict_1.default.deepEqual(groups[0].polish.map((d) => d.decision), ['b2']);
|
|
161
|
-
strict_1.default.deepEqual(groups[1].items.map((d) => d.decision), ['a2']);
|
|
162
|
-
strict_1.default.deepEqual(groups[1].polish.map((d) => d.decision), ['a1']);
|
|
163
|
-
strict_1.default.ok((0, rules_1.rules)(undefined, { cwd, pending: true }).includes('confirm all with'));
|
|
164
|
-
});
|
|
165
|
-
(0, node_test_1.test)('archive entries written before level/change existed still parse', () => {
|
|
166
|
-
const cwd = tmp();
|
|
167
|
-
const p = (0, store_1.resolvePaths)(cwd);
|
|
168
|
-
node_fs_1.default.mkdirSync(p.archiveDir, { recursive: true });
|
|
169
|
-
node_fs_1.default.writeFileSync(p.archive, `# Decision archive
|
|
170
|
-
|
|
171
|
-
### D-0001 · Old rule
|
|
172
|
-
|
|
173
|
-
- **Rationale:** because
|
|
174
|
-
- **Trigger:** old build
|
|
175
|
-
- **Scope:** global · **Dimension:** visual · **Class:** mechanical · **Verdict:** rule
|
|
176
|
-
- **Author:** t · **Date:** 2026-09-01T00:00:00Z · **Commit:** — · **Supersedes:** —
|
|
177
|
-
`);
|
|
178
|
-
const [d] = (0, store_1.readArchive)(p);
|
|
179
|
-
strict_1.default.equal(d.level, 'pattern');
|
|
180
|
-
strict_1.default.equal(d.change, null);
|
|
181
|
-
strict_1.default.equal(d.decision, 'Old rule');
|
|
182
|
-
});
|
|
183
|
-
(0, node_test_1.test)('a ticket ref rides from the flag or the payload through queue and judge', () => {
|
|
184
|
-
const cwd = tmp();
|
|
185
|
-
const p = (0, store_1.resolvePaths)(cwd);
|
|
186
|
-
// --ref on the command wins over the payload; a bare key is fine.
|
|
187
|
-
(0, record_1.queue)(input({ verdict: undefined, ref: 'https://linear.app/acme/issue/ENG-1' }), { cwd, author: 'test', ref: 'ENG-2' });
|
|
188
|
-
// Payload only.
|
|
189
|
-
(0, record_1.queue)(input({ verdict: undefined, decision: 'Empty states are one line', scope: 'pattern:empty-state', dimension: 'states', ref: 'https://github.com/acme/app/issues/42' }), { cwd, author: 'test' });
|
|
190
|
-
// None mentioned.
|
|
191
|
-
(0, record_1.queue)(input({ verdict: undefined, decision: 'Toasts sit bottom-left', scope: 'pattern:toast', dimension: 'states' }), { cwd, author: 'test' });
|
|
192
|
-
strict_1.default.deepEqual((0, store_1.readPending)(p).map((d) => d.ref), ['ENG-2', 'https://github.com/acme/app/issues/42', null]);
|
|
193
|
-
// Judging keeps it; a bulk judge can stamp one on everything left.
|
|
194
|
-
strict_1.default.equal((0, record_1.judge)('P-0001', { cwd, author: 'test', as: 'rule' }).exitCode, 0);
|
|
195
|
-
strict_1.default.equal((0, record_1.judgeAll)({ cwd, author: 'test', as: 'accept', ref: 'ENG-9' }).exitCode, 0);
|
|
196
|
-
strict_1.default.deepEqual((0, store_1.readArchive)(p).map((d) => [d.id, d.ref]), [['D-0001', 'ENG-2'], ['D-0002', 'ENG-9'], ['D-0003', 'ENG-9']]);
|
|
197
|
-
// And it's in the file as its own line, so a URL never collides with the separator.
|
|
198
|
-
strict_1.default.match(node_fs_1.default.readFileSync(p.archive, 'utf8'), /^- \*\*Ref:\*\* ENG-2$/m);
|
|
199
|
-
});
|
|
200
|
-
(0, node_test_1.test)('first /arbiter: the queue reports firstRun until setup records the check-in answer', () => {
|
|
201
|
-
const cwd = node_fs_1.default.mkdtempSync(node_path_1.default.join(node_os_1.default.tmpdir(), 'arbiter-onboard-'));
|
|
202
|
-
(0, store_1.writeConfig)((0, store_1.resolvePaths)(cwd), { version: 1, destination: 'local', author: 'test' });
|
|
203
|
-
const before = JSON.parse((0, rules_1.rules)(undefined, { cwd, pending: true, json: true }));
|
|
204
|
-
strict_1.default.equal(before.firstRun, true);
|
|
205
|
-
strict_1.default.equal(before.checkin, 'feature');
|
|
206
|
-
const r = (0, setup_1.setup)({ cwd, checkin: 'quiet' });
|
|
207
|
-
strict_1.default.equal(r.exitCode, 0);
|
|
208
|
-
const after = JSON.parse((0, rules_1.rules)(undefined, { cwd, pending: true, json: true }));
|
|
209
|
-
strict_1.default.equal(after.firstRun, false);
|
|
210
|
-
strict_1.default.equal(after.checkin, 'quiet');
|
|
211
|
-
const queued = (0, record_1.queue)(JSON.stringify({ change: 'c', decision: 'd', rationale: 'r', trigger: 'T', scope: 'global', dimension: 'visual', class: 'judgment', level: 'polish' }), { cwd, author: 'test' });
|
|
212
|
-
strict_1.default.equal(queued.output.checkin, 'quiet', 'record --pending tells the agent the setting');
|
|
213
|
-
strict_1.default.equal((0, setup_1.setup)({ cwd, checkin: 'loud' }).exitCode, 1, 'unknown modes are refused');
|
|
214
|
-
});
|
package/dist/test/polish.test.js
DELETED
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const node_test_1 = require("node:test");
|
|
7
|
-
const strict_1 = __importDefault(require("node:assert/strict"));
|
|
8
|
-
const node_fs_1 = __importDefault(require("node:fs"));
|
|
9
|
-
const node_os_1 = __importDefault(require("node:os"));
|
|
10
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
11
|
-
const node_http_1 = __importDefault(require("node:http"));
|
|
12
|
-
const record_1 = require("../commands/record");
|
|
13
|
-
const candidate_1 = require("../commands/candidate");
|
|
14
|
-
const review_1 = require("../commands/review");
|
|
15
|
-
const drift_1 = require("../commands/drift");
|
|
16
|
-
const rules_1 = require("../commands/rules");
|
|
17
|
-
const store_1 = require("../store");
|
|
18
|
-
const verify_1 = require("../verify");
|
|
19
|
-
const candidates_1 = require("../candidates");
|
|
20
|
-
const tmp = () => node_fs_1.default.mkdtempSync(node_path_1.default.join(node_os_1.default.tmpdir(), 'arbiter-polish-'));
|
|
21
|
-
const write = (cwd, rel, text) => { node_fs_1.default.mkdirSync(node_path_1.default.join(cwd, node_path_1.default.dirname(rel)), { recursive: true }); node_fs_1.default.writeFileSync(node_path_1.default.join(cwd, rel), text); };
|
|
22
|
-
const rule = (over = {}) => JSON.stringify({ decision: 'Modals for destructive actions', rationale: 'r', trigger: 't', scope: 'pattern:destructive', dimension: 'interaction', class: 'judgment', verdict: 'rule', ...over });
|
|
23
|
-
(0, node_test_1.test)('retire drops a rule with no replacement; archive keeps both; status reads retired', () => {
|
|
24
|
-
const cwd = tmp();
|
|
25
|
-
const o = { cwd, author: 'test' };
|
|
26
|
-
(0, record_1.record)(rule(), o);
|
|
27
|
-
strict_1.default.equal((0, record_1.retire)('D-0001', undefined, o).exitCode, 1, 'why is required');
|
|
28
|
-
strict_1.default.equal((0, record_1.retire)('D-0009', 'x', o).exitCode, 1, 'must be active');
|
|
29
|
-
const r = (0, record_1.retire)('D-0001', 'Component library handles it now', o);
|
|
30
|
-
strict_1.default.equal(r.exitCode, 0);
|
|
31
|
-
strict_1.default.equal(r.output.verdict, 'retire');
|
|
32
|
-
strict_1.default.equal(r.output.supersedes, 'D-0001');
|
|
33
|
-
const p = (0, store_1.resolvePaths)(cwd);
|
|
34
|
-
strict_1.default.equal((0, store_1.readActive)(p).length, 0);
|
|
35
|
-
strict_1.default.equal((0, store_1.readArchive)(p).length, 2);
|
|
36
|
-
strict_1.default.ok((0, rules_1.rules)('D-0001', { cwd }).includes('retired by D-0002'));
|
|
37
|
-
strict_1.default.ok((0, rules_1.rules)(undefined, { cwd, archive: true }).includes('retired by D-0002'));
|
|
38
|
-
strict_1.default.equal((0, record_1.retire)('D-0001', 'again', o).exitCode, 1, 'cannot retire twice');
|
|
39
|
-
});
|
|
40
|
-
(0, node_test_1.test)('regex: needles work in verify and sweep', () => {
|
|
41
|
-
const cwd = tmp();
|
|
42
|
-
write(cwd, 'a.css', 'color: #3b7be0;');
|
|
43
|
-
const r = (0, verify_1.verify)(cwd, ['a.css'], { absent: ['regex:#[0-9a-fA-F]{6}\\b'] });
|
|
44
|
-
strict_1.default.equal(r.ok, false);
|
|
45
|
-
strict_1.default.ok((0, verify_1.verify)(cwd, ['a.css'], { present: ['regex:color:\\s*#'] }).ok);
|
|
46
|
-
const rec = (0, record_1.record)(rule({ class: 'mechanical', dimension: 'visual', scope: 'global', expect: { absent: ['regex:#[0-9a-fA-F]{6}\\b'] } }), { cwd, author: 'test' });
|
|
47
|
-
strict_1.default.equal(rec.output.sweep.violations, 1);
|
|
48
|
-
});
|
|
49
|
-
(0, node_test_1.test)('drift counts accepts and rule breaks per screen', () => {
|
|
50
|
-
const cwd = tmp();
|
|
51
|
-
const o = { cwd, author: 'test' };
|
|
52
|
-
write(cwd, 'src/Badge.tsx', '"#3B7BE0"');
|
|
53
|
-
write(cwd, 'src/Card.tsx', 'brand-500');
|
|
54
|
-
(0, record_1.record)(rule({ class: 'mechanical', dimension: 'visual', scope: 'global', expect: { absent: ['#3B7BE0'] }, files: ['src/Card.tsx'] }), o);
|
|
55
|
-
(0, candidate_1.addCandidate)('Billing', { ...o, feature: 'billing' });
|
|
56
|
-
(0, record_1.record)(rule({ verdict: 'accept', class: 'mechanical', dimension: 'visual', scope: 'file:src/Badge.tsx', files: ['src/Badge.tsx'] }), { ...o, candidate: 'C-0001' });
|
|
57
|
-
const j = JSON.parse((0, drift_1.drift)({ cwd, json: true }));
|
|
58
|
-
strict_1.default.equal(j.screens[0].accepts, 1);
|
|
59
|
-
strict_1.default.deepEqual(j.screens[0].broken.map((b) => b.id), ['D-0001']);
|
|
60
|
-
strict_1.default.ok((0, drift_1.drift)({ cwd }).includes('1 rule broken'));
|
|
61
|
-
});
|
|
62
|
-
(0, node_test_1.test)('review page serves candidates, snapshots, and candidate actions', async () => {
|
|
63
|
-
const cwd = tmp();
|
|
64
|
-
const o = { cwd, author: 'test' };
|
|
65
|
-
write(cwd, 'shot.svg', '<svg xmlns="http://www.w3.org/2000/svg"/>');
|
|
66
|
-
(0, candidate_1.addCandidate)('A', { ...o, feature: 'f', snapshot: 'shot.svg' });
|
|
67
|
-
(0, candidate_1.addCandidate)('B', { ...o, feature: 'f' });
|
|
68
|
-
(0, record_1.queue)(rule(), { ...o, candidate: 'C-0001' });
|
|
69
|
-
const port = 48000 + Math.floor(Math.random() * 1000);
|
|
70
|
-
const done = (0, review_1.review)({ cwd, port, open: false });
|
|
71
|
-
await new Promise((r) => setTimeout(r, 200));
|
|
72
|
-
const state = await get(port, '/api/state');
|
|
73
|
-
strict_1.default.equal(state.candidates.length, 2);
|
|
74
|
-
strict_1.default.equal(state.pending[0].snapshotUrl, '/snapshots/C-0001.svg');
|
|
75
|
-
strict_1.default.equal(state.pending[0].candidateName, 'A');
|
|
76
|
-
strict_1.default.equal((await getRaw(port, '/snapshots/C-0001.svg')).status, 200);
|
|
77
|
-
strict_1.default.equal((await getRaw(port, '/snapshots/../arbiter.json')).status, 404);
|
|
78
|
-
const up = await post(port, '/api/candidate', { id: 'C-0001', state: 'approved', why: 'because' });
|
|
79
|
-
strict_1.default.equal(up.exitCode, 0);
|
|
80
|
-
strict_1.default.deepEqual(up.superseded, ['C-0002']);
|
|
81
|
-
strict_1.default.equal((0, candidates_1.readCandidates)((0, store_1.resolvePaths)(cwd))[1].reason, 'because');
|
|
82
|
-
await post(port, '/api/done', {});
|
|
83
|
-
await done;
|
|
84
|
-
});
|
|
85
|
-
function getRaw(port, p) {
|
|
86
|
-
return new Promise((resolve, reject) => {
|
|
87
|
-
node_http_1.default.get({ host: '127.0.0.1', port, path: p }, (res) => { res.resume(); res.on('end', () => resolve({ status: res.statusCode })); }).on('error', reject);
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
function get(port, p) {
|
|
91
|
-
return new Promise((resolve, reject) => {
|
|
92
|
-
node_http_1.default.get({ host: '127.0.0.1', port, path: p }, (res) => { let d = ''; res.on('data', (c) => (d += c)); res.on('end', () => resolve(JSON.parse(d))); }).on('error', reject);
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
function post(port, p, body) {
|
|
96
|
-
return new Promise((resolve, reject) => {
|
|
97
|
-
const req = node_http_1.default.request({ host: '127.0.0.1', port, path: p, method: 'POST', headers: { 'content-type': 'application/json' } }, (res) => { let d = ''; res.on('data', (c) => (d += c)); res.on('end', () => resolve(JSON.parse(d))); });
|
|
98
|
-
req.on('error', reject);
|
|
99
|
-
req.end(JSON.stringify(body));
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
(0, node_test_1.test)('export writes a self-contained folder: index.html, snapshots, stakeholder view only', () => {
|
|
103
|
-
const cwd = tmp();
|
|
104
|
-
const o = { cwd, author: 'test' };
|
|
105
|
-
write(cwd, 'shot.svg', '<svg xmlns="http://www.w3.org/2000/svg"/>');
|
|
106
|
-
(0, candidate_1.addCandidate)('Settings — single <page>', { ...o, feature: 'settings', snapshot: 'shot.svg' });
|
|
107
|
-
(0, candidate_1.addCandidate)('Settings — tabs', { ...o, feature: 'settings' });
|
|
108
|
-
(0, candidate_1.addCandidate)('Billing', { ...o, feature: 'billing' });
|
|
109
|
-
(0, record_1.record)(rule({ change: 'Danger zone is at the bottom', decision: 'Destructive settings live last', rejected: ['Tabs — hid it'] }), { ...o, candidate: 'C-0001' });
|
|
110
|
-
(0, record_1.record)(rule({ decision: 'h-9', level: 'polish', scope: 'file:x', verdict: 'accept' }), { ...o, candidate: 'C-0001' });
|
|
111
|
-
(0, record_1.queue)(rule({ decision: 'Pending thing', scope: 'pattern:pending' }), { ...o, candidate: 'C-0001' });
|
|
112
|
-
(0, candidate_1.updateCandidate)('C-0001', { ...o, state: 'approved', why: 'tabs hid it' });
|
|
113
|
-
const { exportBoard } = require('../commands/export');
|
|
114
|
-
const r = exportBoard({ cwd, includeRules: true });
|
|
115
|
-
strict_1.default.equal(r.candidates, 3);
|
|
116
|
-
strict_1.default.equal(r.snapshots, 1);
|
|
117
|
-
const html = node_fs_1.default.readFileSync(r.index, 'utf8');
|
|
118
|
-
strict_1.default.ok(node_fs_1.default.existsSync(node_path_1.default.join(r.dir, 'snapshots', 'C-0001.svg')));
|
|
119
|
-
strict_1.default.ok(html.includes('Settings — single <page>'), 'escaped');
|
|
120
|
-
strict_1.default.ok(html.includes('Superseded by Settings — single <page>'));
|
|
121
|
-
strict_1.default.ok(html.includes('Danger zone is at the bottom'), 'Change text, not rule text');
|
|
122
|
-
strict_1.default.ok(html.includes('over Tabs'));
|
|
123
|
-
strict_1.default.ok(!html.includes('h-9'), 'polish omitted');
|
|
124
|
-
strict_1.default.ok(!html.includes('Pending thing'), 'pending omitted');
|
|
125
|
-
strict_1.default.ok(html.includes('Standing rules'));
|
|
126
|
-
strict_1.default.ok(!html.includes('Make it a rule'), 'no verdict controls');
|
|
127
|
-
const one = exportBoard({ cwd, feature: 'billing', out: 'out-billing' });
|
|
128
|
-
strict_1.default.equal(one.candidates, 1);
|
|
129
|
-
strict_1.default.ok(!node_fs_1.default.readFileSync(one.index, 'utf8').includes('Settings'));
|
|
130
|
-
});
|