@yairabf/engineering-workflows 0.0.0-stage → 1.0.0
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/.agents/skills/grill-me/SKILL.md +7 -0
- package/.agents/skills/grill-me/agents/openai.yaml +5 -0
- package/.agents/skills/grilling/SKILL.md +28 -0
- package/.agents/skills/grilling/agents/openai.yaml +3 -0
- package/engineering-workflows/.agents/skills/workflow-implement/SKILL.md +17 -0
- package/engineering-workflows/.agents/skills/workflow-implement/references/implementation-handoff.md +17 -0
- package/engineering-workflows/.agents/skills/workflow-initiate/SKILL.md +49 -0
- package/engineering-workflows/.agents/skills/workflow-initiate/references/preparation.md +80 -0
- package/engineering-workflows/.agents/skills/workflow-initiate/references/prerequisites.json +53 -0
- package/engineering-workflows/.agents/skills/workflow-initiate/references/readiness.md +87 -0
- package/engineering-workflows/.agents/skills/workflow-initiate/scripts/marker.mjs +97 -0
- package/engineering-workflows/.agents/skills/workflow-investigate/SKILL.md +55 -0
- package/engineering-workflows/.agents/skills/workflow-investigate/references/investigation-brief.md +38 -0
- package/engineering-workflows/.agents/skills/workflow-plan/SKILL.md +46 -0
- package/engineering-workflows/.agents/skills/workflow-plan/references/implementation-plan.md +31 -0
- package/engineering-workflows/.agents/skills/workflow-review/SKILL.md +56 -0
- package/engineering-workflows/.agents/skills/workflow-review/references/independent-review.md +29 -0
- package/engineering-workflows/.claude/skills/workflow-implement/SKILL.md +10 -0
- package/engineering-workflows/.claude/skills/workflow-initiate/SKILL.md +10 -0
- package/engineering-workflows/.claude/skills/workflow-investigate/SKILL.md +10 -0
- package/engineering-workflows/.claude/skills/workflow-plan/SKILL.md +10 -0
- package/engineering-workflows/.claude/skills/workflow-review/SKILL.md +10 -0
- package/engineering-workflows/README.md +282 -0
- package/engineering-workflows/builder/delivery.mjs +177 -0
- package/engineering-workflows/builder/delivery.test.mjs +154 -0
- package/engineering-workflows/builder/drive.mjs +184 -0
- package/engineering-workflows/builder/drive.test.mjs +350 -0
- package/engineering-workflows/builder/handoff.mjs +40 -0
- package/engineering-workflows/builder/mission-role.mjs +294 -0
- package/engineering-workflows/builder/pi-session.mjs +45 -0
- package/engineering-workflows/builder/reader-guard.mjs +58 -0
- package/engineering-workflows/builder/role-session.mjs +42 -0
- package/engineering-workflows/builder/stage.mjs +446 -0
- package/engineering-workflows/builder/workspace-tool.mjs +20 -0
- package/engineering-workflows/builder-plan.mjs +174 -0
- package/engineering-workflows/builder-project.mjs +117 -0
- package/engineering-workflows/check-package-visibility.mjs +54 -0
- package/engineering-workflows/install.mjs +182 -0
- package/engineering-workflows/mission/README.md +281 -0
- package/engineering-workflows/mission/controller.mjs +54 -0
- package/engineering-workflows/mission/mission-controller.test.mjs +382 -0
- package/engineering-workflows/mission/mission-mcp.test.mjs +102 -0
- package/engineering-workflows/mission/status.mjs +113 -0
- package/engineering-workflows/mission/store.mjs +180 -0
- package/engineering-workflows/mission/tools.mjs +54 -0
- package/engineering-workflows/mission/transitions.mjs +269 -0
- package/engineering-workflows/mission-controller.mjs +72 -0
- package/engineering-workflows/mission-mcp.mjs +66 -0
- package/engineering-workflows/prerequisites.mjs +205 -0
- package/engineering-workflows/readiness.mjs +263 -0
- package/engineering-workflows/release-targets.mjs +12 -0
- package/engineering-workflows/setup.mjs +70 -0
- package/engineering-workflows/stage-release.mjs +45 -0
- package/engineering-workflows/upgrade.mjs +333 -0
- package/engineering-workflows/workflows/development.md +372 -0
- package/engineering-workflows/workflows/engineering-workflows.yml +90 -0
- package/package.json +21 -4
- package/README.md +0 -3
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
import test from 'node:test'
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
3
|
+
import { execFileSync } from 'node:child_process'
|
|
4
|
+
import { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
|
|
5
|
+
import { tmpdir } from 'node:os'
|
|
6
|
+
import { join } from 'node:path'
|
|
7
|
+
import { checkoutReview, drive, validatedKind } from './drive.mjs'
|
|
8
|
+
import { roleInputs } from './mission-role.mjs'
|
|
9
|
+
|
|
10
|
+
function temporary(t) {
|
|
11
|
+
const root = mkdtempSync(join(tmpdir(), 'ew-check-'))
|
|
12
|
+
t.after(() => rmSync(root, { recursive: true, force: true }))
|
|
13
|
+
return root
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
test('reviews committed files even when the developer directory contains local edits and ignored files', (t) => {
|
|
17
|
+
const root = temporary(t)
|
|
18
|
+
const git = (args) =>
|
|
19
|
+
execFileSync('git', args, { cwd: root, stdio: ['ignore', 'pipe', 'pipe'], encoding: 'utf8' }).trim()
|
|
20
|
+
git(['init', '-q'])
|
|
21
|
+
writeFileSync(join(root, '.gitignore'), 'generated\n')
|
|
22
|
+
writeFileSync(join(root, 'app'), 'committed')
|
|
23
|
+
git(['add', '.'])
|
|
24
|
+
git(['-c', 'user.name=Test', '-c', 'user.email=test@localhost', 'commit', '-qm', 'Initial'])
|
|
25
|
+
const sha = git(['rev-parse', 'HEAD'])
|
|
26
|
+
writeFileSync(join(root, 'app'), 'changed')
|
|
27
|
+
writeFileSync(join(root, 'generated'), 'leftover')
|
|
28
|
+
const bundle = join(root, 'test.bundle')
|
|
29
|
+
git(['bundle', 'create', bundle, 'HEAD'])
|
|
30
|
+
const workspace = join(root, 'review')
|
|
31
|
+
checkoutReview(git, workspace, bundle, sha)
|
|
32
|
+
assert.equal(readFileSync(join(workspace, 'app'), 'utf8'), 'committed')
|
|
33
|
+
assert.equal(existsSync(join(workspace, 'generated')), false)
|
|
34
|
+
assert.equal(git(['-C', workspace, 'rev-parse', 'HEAD']), sha)
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
test('investigation requires documented findings with evidence and the starting revision', () => {
|
|
38
|
+
const url = 'https://github.com/test/demo/issues/1',
|
|
39
|
+
base = 'a'.repeat(40)
|
|
40
|
+
const p = { kind: 'brief', base }
|
|
41
|
+
const brief = [
|
|
42
|
+
url,
|
|
43
|
+
'## Mission',
|
|
44
|
+
'Test',
|
|
45
|
+
'## Repository context',
|
|
46
|
+
base,
|
|
47
|
+
'## Verified findings',
|
|
48
|
+
'- **Finding:** No tests\n - **Evidence:** git ls-files returned no files.',
|
|
49
|
+
'## Assumptions',
|
|
50
|
+
'None',
|
|
51
|
+
'## Open questions and evidence gaps',
|
|
52
|
+
'None',
|
|
53
|
+
'## Skipped checks',
|
|
54
|
+
'None',
|
|
55
|
+
].join('\n')
|
|
56
|
+
assert.equal(validatedKind(p, null, brief, url), 'brief')
|
|
57
|
+
for (const bad of [brief.replace(base, 'unknown'), brief.replace('**Evidence:**', '**Unverified:**')])
|
|
58
|
+
assert.throws(() => validatedKind(p, null, bad, url))
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
test('repair receives saved operator instructions', (t) => {
|
|
62
|
+
const root = temporary(t),
|
|
63
|
+
store = { artifact: (name) => join(root, name) }
|
|
64
|
+
for (const name of ['mission', 'approved', 'candidate', 'review', 'decision'])
|
|
65
|
+
writeFileSync(store.artifact(name), name === 'decision' ? 'Keep the older schema' : name)
|
|
66
|
+
const prompt = roleInputs(
|
|
67
|
+
{
|
|
68
|
+
stage: 'repair',
|
|
69
|
+
file: 'mission',
|
|
70
|
+
notes: [{ kind: 'continue', file: 'decision' }],
|
|
71
|
+
plans: [{ approved: 'approved' }],
|
|
72
|
+
candidates: [{ file: 'candidate', reviews: [{ file: 'review' }] }],
|
|
73
|
+
},
|
|
74
|
+
store,
|
|
75
|
+
)
|
|
76
|
+
assert.match(prompt, /Keep the older schema/)
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
test('failed workspace launch records the revision and cleans the scratch directory', async () => {
|
|
80
|
+
const calls = []
|
|
81
|
+
const docker = (args) => {
|
|
82
|
+
calls.push(args)
|
|
83
|
+
if (args[0] === 'run') throw Error('launch failed')
|
|
84
|
+
return 'image'
|
|
85
|
+
}
|
|
86
|
+
const stage = (_writer, op, data) => {
|
|
87
|
+
calls.push([op, data])
|
|
88
|
+
return JSON.stringify({
|
|
89
|
+
workspace: '/root/role-workspaces/session/checkout',
|
|
90
|
+
scratch: true,
|
|
91
|
+
kind: 'brief',
|
|
92
|
+
stage: 'investigation',
|
|
93
|
+
revision: 2,
|
|
94
|
+
})
|
|
95
|
+
}
|
|
96
|
+
await assert.rejects(drive({ docker, stage, writer: 'writer', root: '/root', source: '/host' }), /launch failed/)
|
|
97
|
+
assert.deepEqual(calls.at(-1), ['exec', 'writer', 'rm', '-rf', '--', '/root/role-workspaces/session'])
|
|
98
|
+
assert.deepEqual(calls.at(-2), ['failure', { revision: 2, reason: 'launch failed' }])
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
test('unchanged PR refresh needs no workspace container or bundle', async () => {
|
|
102
|
+
const calls = []
|
|
103
|
+
const result = await drive({
|
|
104
|
+
docker: (args) => {
|
|
105
|
+
calls.push(args[0])
|
|
106
|
+
return 'image'
|
|
107
|
+
},
|
|
108
|
+
stage: (_writer, op) =>
|
|
109
|
+
op === 'packet' ? JSON.stringify({ kind: 'delivery', refresh: true, revision: 9 }) : 'delivery status',
|
|
110
|
+
})
|
|
111
|
+
assert.equal(result, 'delivery status')
|
|
112
|
+
assert.deepEqual(calls, ['inspect'])
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
test('planner must complete the template and name the saved investigation brief', () => {
|
|
116
|
+
const url = 'https://github.com/example/demo/issues/7',
|
|
117
|
+
briefName = 'brief-' + 'a'.repeat(64) + '.md'
|
|
118
|
+
const template = readFileSync(
|
|
119
|
+
new URL('../.agents/skills/workflow-plan/references/implementation-plan.md', import.meta.url),
|
|
120
|
+
'utf8',
|
|
121
|
+
)
|
|
122
|
+
const incomplete = template
|
|
123
|
+
.replace(/<original file or source reference and target repository>/, url)
|
|
124
|
+
.replace(/<file reference and inspected revision, if known>/, briefName)
|
|
125
|
+
const p = { kind: 'plan', briefName }
|
|
126
|
+
assert.throws(() => validatedKind(p, null, incomplete, url), /placeholders/)
|
|
127
|
+
const complete = incomplete.replace(/<[^<>]+>/g, 'Document the repository test command.')
|
|
128
|
+
assert.equal(validatedKind(p, null, complete, url), 'plan')
|
|
129
|
+
assert.throws(() => validatedKind(p, null, complete.replace(briefName, 'brief.md'), url), /reference the brief/)
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
test('operator reconciles a rejected captured handoff at the same revision before resume', async (t) => {
|
|
133
|
+
const { openStore } = await import('../mission/store.mjs')
|
|
134
|
+
const { fileURLToPath } = await import('node:url')
|
|
135
|
+
const root = temporary(t),
|
|
136
|
+
url = 'https://github.com/example/demo/issues/7'
|
|
137
|
+
const store = openStore(join(root, 'mission-state'), process.cwd(), true)
|
|
138
|
+
const artifact = (kind) => store.saveArtifact(kind, url + '\n' + kind)
|
|
139
|
+
const approved = artifact('approved-plan'),
|
|
140
|
+
sha = 'a'.repeat(40),
|
|
141
|
+
branch = 'workflow/issue-7'
|
|
142
|
+
const workspace = join(root, 'role-workspaces', 'implementation')
|
|
143
|
+
const stage = (op, data) =>
|
|
144
|
+
execFileSync(
|
|
145
|
+
process.execPath,
|
|
146
|
+
[fileURLToPath(new URL('./stage.mjs', import.meta.url)), op, root, 'example/demo', '7'],
|
|
147
|
+
{ encoding: 'utf8', stdio: ['pipe', 'pipe', 'pipe'], input: JSON.stringify(data) },
|
|
148
|
+
).trim()
|
|
149
|
+
store.save(1, 'a'.repeat(64), {
|
|
150
|
+
repository: 'example/demo',
|
|
151
|
+
number: 7,
|
|
152
|
+
file: artifact('mission'),
|
|
153
|
+
stage: 'implementation',
|
|
154
|
+
notes: [],
|
|
155
|
+
plans: [{ file: artifact('plan'), approved }],
|
|
156
|
+
candidates: [],
|
|
157
|
+
delivery: [],
|
|
158
|
+
failedRepairs: 0,
|
|
159
|
+
round: 0,
|
|
160
|
+
brief: artifact('brief'),
|
|
161
|
+
ready: { file: artifact('ready'), base: 'main', checkout: root },
|
|
162
|
+
})
|
|
163
|
+
stage('capture', { revision: 1, document: url })
|
|
164
|
+
const packet = {
|
|
165
|
+
kind: 'candidate',
|
|
166
|
+
workspace,
|
|
167
|
+
branch,
|
|
168
|
+
base: 'b'.repeat(40),
|
|
169
|
+
stage: 'implementation',
|
|
170
|
+
revision: 1,
|
|
171
|
+
url,
|
|
172
|
+
}
|
|
173
|
+
const run = () =>
|
|
174
|
+
drive({
|
|
175
|
+
writer: 'writer',
|
|
176
|
+
root,
|
|
177
|
+
source: '/host',
|
|
178
|
+
docker: (args) => (args.includes('rev-parse') ? sha : args.includes('branch') ? branch : ''),
|
|
179
|
+
stage: (_writer, op, data) => {
|
|
180
|
+
if (op === 'packet') {
|
|
181
|
+
if (store.revisions()[0] === 2) return '{}'
|
|
182
|
+
const name = readFileSync(join(store.root, 'role-result-1'), 'utf8')
|
|
183
|
+
return JSON.stringify({ ...packet, captured: readFileSync(store.artifact(name), 'utf8') })
|
|
184
|
+
}
|
|
185
|
+
if (op === 'resume') return store.read(2).mission.stage
|
|
186
|
+
return stage(op, data)
|
|
187
|
+
},
|
|
188
|
+
})
|
|
189
|
+
await assert.rejects(run(), /Candidate commit/)
|
|
190
|
+
const document = [
|
|
191
|
+
url,
|
|
192
|
+
'**Target:** example/demo',
|
|
193
|
+
'**Approved plan:** ' + approved,
|
|
194
|
+
'**Branch:** ' + branch,
|
|
195
|
+
'**Worktree:** ' + workspace,
|
|
196
|
+
'**Candidate commit:** ' + sha,
|
|
197
|
+
'## Verification',
|
|
198
|
+
'Tests passed.',
|
|
199
|
+
].join('\n')
|
|
200
|
+
assert.throws(() => stage('operator', { command: 'recover-handoff', revision: 2, document }), /current revision/)
|
|
201
|
+
stage('operator', { command: 'recover-handoff', revision: 1, document })
|
|
202
|
+
assert.equal(await run(), 'review')
|
|
203
|
+
})
|
|
204
|
+
|
|
205
|
+
test('recovers a second changed head and cleans scratch storage on packet failure', async (t) => {
|
|
206
|
+
const { openStore } = await import('../mission/store.mjs')
|
|
207
|
+
const { fileURLToPath } = await import('node:url')
|
|
208
|
+
const { readdirSync, mkdirSync } = await import('node:fs')
|
|
209
|
+
const root = temporary(t)
|
|
210
|
+
const git = (...args) => execFileSync('git', args, { cwd: root, encoding: 'utf8' }).trim()
|
|
211
|
+
git('init', '-qb', 'main')
|
|
212
|
+
const commit = (title) => {
|
|
213
|
+
git('-c', 'user.name=Test', '-c', 'user.email=test@example.invalid', 'commit', '-qm', title, '--allow-empty')
|
|
214
|
+
return git('rev-parse', 'HEAD')
|
|
215
|
+
}
|
|
216
|
+
const original = commit('original'),
|
|
217
|
+
first = commit('first'),
|
|
218
|
+
latest = commit('second')
|
|
219
|
+
git('update-ref', 'refs/pull/1/head', latest)
|
|
220
|
+
const config = join(root, 'gitconfig')
|
|
221
|
+
git('config', '--file', config, 'url.' + root + '.insteadOf', 'https://github.com/example/demo.git')
|
|
222
|
+
const bin = join(root, 'bin')
|
|
223
|
+
mkdirSync(bin)
|
|
224
|
+
writeFileSync(join(bin, 'gh'), '#!/bin/sh\necho ' + latest + '\n', { mode: 0o700 })
|
|
225
|
+
const store = openStore(join(root, 'mission-state'), process.cwd(), true)
|
|
226
|
+
const art = (k) => store.saveArtifact(k, k)
|
|
227
|
+
const ready = store.saveArtifact('ready', '**Starting commit:** ' + original)
|
|
228
|
+
store.save(1, 'a'.repeat(64), {
|
|
229
|
+
stage: 'delivery-head-changed',
|
|
230
|
+
repository: 'example/demo',
|
|
231
|
+
number: 7,
|
|
232
|
+
file: art('mission'),
|
|
233
|
+
brief: art('brief'),
|
|
234
|
+
plans: [{ file: art('plan'), approved: art('approved-plan') }],
|
|
235
|
+
ready: { file: ready, base: 'main', checkout: root },
|
|
236
|
+
notes: [],
|
|
237
|
+
round: 0,
|
|
238
|
+
failedRepairs: 0,
|
|
239
|
+
candidates: [
|
|
240
|
+
{
|
|
241
|
+
file: art('candidate'),
|
|
242
|
+
sha: original,
|
|
243
|
+
evidence: art('checks'),
|
|
244
|
+
reviews: [],
|
|
245
|
+
round: 0,
|
|
246
|
+
branch: 'workflow/issue-7',
|
|
247
|
+
},
|
|
248
|
+
],
|
|
249
|
+
delivery: [
|
|
250
|
+
{ file: art('delivery'), head: first, pr: 'https://github.com/example/demo/pull/1', changed: true },
|
|
251
|
+
],
|
|
252
|
+
})
|
|
253
|
+
const run = (op) =>
|
|
254
|
+
execFileSync(
|
|
255
|
+
process.execPath,
|
|
256
|
+
[fileURLToPath(new URL('./stage.mjs', import.meta.url)), op, root, 'example/demo', '7'],
|
|
257
|
+
{
|
|
258
|
+
encoding: 'utf8',
|
|
259
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
260
|
+
env: { ...process.env, PATH: bin + ':' + process.env.PATH, GIT_CONFIG_GLOBAL: config },
|
|
261
|
+
},
|
|
262
|
+
)
|
|
263
|
+
// No Thermo skill in this fixture. The packet fails after recording the correct review target.
|
|
264
|
+
assert.throws(() => run('packet'))
|
|
265
|
+
const saved = store.read(3)
|
|
266
|
+
assert.equal(saved.mission.stage, 'review')
|
|
267
|
+
assert.equal(saved.mission.candidates.at(-1).sha, latest)
|
|
268
|
+
assert.equal(saved.mission.delivery.at(-1).head, latest)
|
|
269
|
+
assert.match(run('resume'), /Last failed attempt:[\s\S]*thermo/i)
|
|
270
|
+
const sessions = readdirSync(join(root, 'role-workspaces', ready))
|
|
271
|
+
assert.equal(sessions.length, 1)
|
|
272
|
+
assert.match(sessions[0], /^pr-head-/)
|
|
273
|
+
})
|
|
274
|
+
|
|
275
|
+
test('builder sends normalized Windows Markdown for disposition, recovery and clarification', async t => {
|
|
276
|
+
const {fileURLToPath} = await import('node:url')
|
|
277
|
+
const root = temporary(t)
|
|
278
|
+
const input = join(root, 'operator.md')
|
|
279
|
+
const document = 'https://github.com/example/demo/issues/7\n\n## Evidence\nBoth tests passed.\n'
|
|
280
|
+
writeFileSync(input, document.replaceAll('\n','\r\n'))
|
|
281
|
+
writeFileSync(join(root, 'docker'), `#!/usr/bin/env node
|
|
282
|
+
const args=process.argv.slice(2)
|
|
283
|
+
if(args[0]==='inspect') console.log(JSON.stringify([{Type:'bind',RW:args.at(-1)==='writer',Source:'/host',Destination:'/projects'}]))
|
|
284
|
+
else if(args.includes('mktemp')) console.log('/tmp/ew-builder.fixture')
|
|
285
|
+
else if(args.includes('operator')) process.stdout.write(require('node:fs').readFileSync(0))
|
|
286
|
+
`, {mode:0o700})
|
|
287
|
+
for (const action of ['delivery','recover-handoff','clarification']) {
|
|
288
|
+
const output = execFileSync(process.execPath,[fileURLToPath(new URL('../builder-plan.mjs',import.meta.url)),
|
|
289
|
+
action,'example/demo','7',input,'3'],{encoding:'utf8',env:{...process.env,EW_BUILDER_WRITER:'writer',
|
|
290
|
+
EW_BUILDER_READER:'reader',PATH:root+':'+process.env.PATH}})
|
|
291
|
+
assert.equal(JSON.parse(output).document,document)
|
|
292
|
+
}
|
|
293
|
+
})
|
|
294
|
+
|
|
295
|
+
test('unchanged implementation and repair commits require a fresh developer session on retry', async () => {
|
|
296
|
+
for (const kind of ['candidate', 'repair']) {
|
|
297
|
+
const branch = 'workflow/issue-7', workspace = '/root/role-workspaces/implementation'
|
|
298
|
+
const packet = { kind, stage: kind === 'repair' ? 'repair' : 'implementation', branch, workspace,
|
|
299
|
+
revision: 3, base: 'b'.repeat(40), candidate: 'c'.repeat(40) }
|
|
300
|
+
let head = kind === 'repair' ? packet.candidate : packet.base
|
|
301
|
+
let sessions = 0, recorded = false
|
|
302
|
+
const run = () => drive({
|
|
303
|
+
root: '/root', source: '/host',
|
|
304
|
+
docker: args => args.includes('rev-parse') ? head : args.includes('branch') ? branch : '',
|
|
305
|
+
stage: (_writer, op, data) => {
|
|
306
|
+
if (op === 'packet') return JSON.stringify(recorded ? {} : packet)
|
|
307
|
+
if (op === 'capture') packet.captured = data.document
|
|
308
|
+
if (op === 'result') recorded = true
|
|
309
|
+
return op
|
|
310
|
+
},
|
|
311
|
+
runRole: () => {
|
|
312
|
+
if (++sessions === 2) head = 'd'.repeat(40)
|
|
313
|
+
return ['**Candidate commit:** ' + head, '**Branch:** ' + branch, '**Worktree:** ' + workspace].join('\n')
|
|
314
|
+
},
|
|
315
|
+
})
|
|
316
|
+
await assert.rejects(run(), /No new candidate commit/)
|
|
317
|
+
assert.equal(recorded, false)
|
|
318
|
+
assert.ok(packet.captured)
|
|
319
|
+
assert.equal(await run(), 'resume')
|
|
320
|
+
assert.equal(sessions, 2)
|
|
321
|
+
assert.equal(recorded, true)
|
|
322
|
+
}
|
|
323
|
+
})
|
|
324
|
+
|
|
325
|
+
test('workspace reports the exit status for passing and failing commands with identical verbose logs', async t => {
|
|
326
|
+
const { roleSession } = await import('./role-session.mjs')
|
|
327
|
+
const root = temporary(t)
|
|
328
|
+
// Stand in for the reader's Pi session and the workspace Docker invocation.
|
|
329
|
+
writeFileSync(join(root, 'docker'), `#!/bin/sh
|
|
330
|
+
case "$3" in
|
|
331
|
+
reader)
|
|
332
|
+
if [ "$4" = sh ]; then cat >/dev/null; exit 0; fi
|
|
333
|
+
printf '{"command":"run"}\\n'
|
|
334
|
+
IFS= read -r reply
|
|
335
|
+
node -e 'console.log(JSON.stringify({result:JSON.parse(process.argv[1]).output}))' "$reply"
|
|
336
|
+
;;
|
|
337
|
+
sh)
|
|
338
|
+
node -e 'process.stdout.write("x".repeat(25000))'
|
|
339
|
+
exit "$2"
|
|
340
|
+
;;
|
|
341
|
+
esac
|
|
342
|
+
`, { mode: 0o700 })
|
|
343
|
+
const previousPath = process.env.PATH
|
|
344
|
+
t.after(() => { process.env.PATH = previousPath })
|
|
345
|
+
process.env.PATH = root + ':' + previousPath
|
|
346
|
+
for (const code of ['0', '1']) {
|
|
347
|
+
const output = await roleSession('reader', root, 'Run the checks', code)
|
|
348
|
+
assert.equal(output, 'exit ' + code + '\n[output truncated]\n' + 'x'.repeat(24000))
|
|
349
|
+
}
|
|
350
|
+
})
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export function checkHandoff(text, template, url, plan, briefName = 'brief.md') {
|
|
2
|
+
if (/^BLOCKED\b/i.test(text)) throw new Error('Role blocked: ' + text.slice(0, 1000))
|
|
3
|
+
const citations = text.match(/https?:\/\/[^\s<>"'`()\[\]]+/gi) ?? []
|
|
4
|
+
if (!citations.some((citation) => citation.replace(/[.,;:!]+$/, '') === url)) {
|
|
5
|
+
throw new Error('Role output does not reference the requested issue.')
|
|
6
|
+
}
|
|
7
|
+
for (const title of template.split('\n').filter((line) => line.startsWith('## '))) {
|
|
8
|
+
const section = text.split('\n' + title + '\n')
|
|
9
|
+
if (section.length !== 2 || !section[1].split('\n## ')[0].trim()) {
|
|
10
|
+
throw new Error('Role returned an incomplete document. Expected one populated section for ' + title)
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
const normalizedText = text.replace(/\s+/g, ' ')
|
|
14
|
+
const placeholders = template.replace(/\s+/g, ' ').match(/<[^<>]+>/g) ?? []
|
|
15
|
+
if (placeholders.some((placeholder) => normalizedText.includes(placeholder))) {
|
|
16
|
+
throw new Error('Role returned an incomplete document with template placeholders.')
|
|
17
|
+
}
|
|
18
|
+
if (!plan) {
|
|
19
|
+
const findings = text.split('\n## Verified findings\n')[1].split('\n## ')[0].trim()
|
|
20
|
+
const [preamble, ...entries] = findings.split(/^[ \t]*[-*] \*\*Finding:\*\*[ \t]*/m)
|
|
21
|
+
if (preamble.trim() || !entries.length)
|
|
22
|
+
throw new Error('Expected findings in the investigation template format.')
|
|
23
|
+
for (const entry of entries) {
|
|
24
|
+
const [finding, evidence] = entry.split(/^[ \t]*[-*] \*\*Evidence:\*\*[ \t]*/m)
|
|
25
|
+
const supportingText = evidence?.split(/^[ \t]*[-*] \*\*/m)[0].trim()
|
|
26
|
+
if (!finding.trim() || !supportingText) throw new Error('Each verified finding needs supporting evidence.')
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
if (plan) {
|
|
30
|
+
const approval = text.split('\n## Human approval\n')[1].trim()
|
|
31
|
+
const decisions = text.match(/^\*\*Decision:\*\*.*$/gm) ?? []
|
|
32
|
+
if (
|
|
33
|
+
decisions.length !== 1 ||
|
|
34
|
+
!/^\*\*Decision:\*\* Pending[ \t]*$/m.test(approval) ||
|
|
35
|
+
!text.includes(briefName)
|
|
36
|
+
) {
|
|
37
|
+
throw new Error('Planner must reference the brief and return one pending human decision.')
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|