levi-gear 0.6.0 → 0.7.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.
@@ -1,14 +1,14 @@
1
1
  export const meta = {
2
2
  name: 'levi-fix-bug',
3
- description: 'Fix a bug with TDD: the developer investigates and fixes it while QA writes the scenarios; the teamlead reviews every fix, then QA runs the scenarios end to end until they all pass',
3
+ description: 'Fix a bug with TDD: the developer investigates and fixes it while QA writes the scenarios; the teamlead reviews every fix, then, when browser tests are on, QA runs the scenarios end to end until they all pass',
4
4
  whenToUse: 'Started by the levi-fix-bug skill once the open points of the bug report are confirmed with the user',
5
5
  phases: [
6
6
  { title: 'Investigate', detail: 'the developer finds the root cause and makes tests fail on the bug; QA writes the scenarios at the same time' },
7
- { title: 'Fix', detail: 'fix, unit and feature tests, teamlead review, E2E; repeat until the review approves and every scenario passes' },
7
+ { title: 'Fix', detail: 'fix, unit and feature tests, teamlead review, E2E when browser tests are on; repeat until the review approves and, with browser tests on, every scenario passes' },
8
8
  ],
9
9
  }
10
10
 
11
- // args: { slug, spec?, designs?, base, allMerged?, featureId?, testBase?, skillDir, maxRounds? } — see the skill's SKILL.md.
11
+ // args: { slug, spec?, designs?, base, allMerged?, featureId?, testBase?, browserTests?, browserScope?, skillDir, maxRounds? } — see the skill's SKILL.md.
12
12
  const A = args || {}
13
13
  const absent = ['slug', 'base', 'skillDir'].filter((k) => !A[k])
14
14
  if (absent.length) return { status: 'error', message: `missing args: ${absent.join(', ')}` }
@@ -32,6 +32,13 @@ const LOCK_TESTS = `${WORK}/locked/tests`
32
32
  const LOCK_SCENARIOS = `${WORK}/locked/scenarios`
33
33
  const MAX_RED = 3
34
34
  const MAX_ROUNDS = A.maxRounds || 10
35
+ // Browser tests (the E2E run) are slow and optional: the user chooses at the start, and a missing value means no.
36
+ const BROWSER = A.browserTests === true
37
+ const BROWSER_SCOPE = BROWSER && A.browserScope ? String(A.browserScope) : ''
38
+ // QA writes and changes test cases with the strongest setting; running them keeps the agent's default.
39
+ const QA_WRITE = { model: 'opus', effort: 'high' }
40
+ // With browser tests off, nothing in the run may open a browser: not the new tests, and not the suite the gate runs.
41
+ const NO_BROWSER = BROWSER ? '' : '\n\nBrowser tests are off for this run: write or rely on no test that opens a browser (an E2E runner, Playwright, a browser project of Vitest), and make every test command you return (testCommand and suiteCommand) leave out the tests that do.'
35
42
 
36
43
  const CONTEXT = [
37
44
  `Bug report, as the user gave it: ${REPORT}`,
@@ -88,6 +95,7 @@ const E2E = obj({
88
95
  status: STATUS,
89
96
  summary: { type: 'string' },
90
97
  results: { type: 'array', items: obj({ id: { type: 'string' }, result: { type: 'string', enum: ['PASS', 'FAIL'] }, evidence: { type: 'string' } }) },
98
+ skipped: { ...STRINGS, description: 'IDs of the cases left out on purpose because of the scope the user set. Empty when no scope was set' },
91
99
  })
92
100
 
93
101
  // ---- helpers ----
@@ -125,7 +133,7 @@ On top of the guide:
125
133
  - Do not record results: you record them later, when you run the cases.
126
134
 
127
135
  Return the number of cases as scenarioCount.`,
128
- { label: 'qa:scenarios', phase: 'Investigate', agentType: 'levi-qa', schema: WRITTEN },
136
+ { label: 'qa:scenarios', phase: 'Investigate', agentType: 'levi-qa', schema: WRITTEN, ...QA_WRITE },
129
137
  )
130
138
  if (!written || written.status === 'BLOCKED') return { stop: 'blocked', detail: written ? written.summary : 'QA did not write the scenarios' }
131
139
  if (questionsOf(written).length) return { stop: 'questions', questions: written.questions }
@@ -147,7 +155,7 @@ Investigate this bug, test first. Do not fix it yet.
147
155
  3. Run them: they must fail now, because of the bug, not because of a typo or a wrong setup.
148
156
 
149
157
  Write ${INVESTIGATION}: expected against actual, the root cause with its locations, other places with the same cause, the tests that cover the bug, and how you will fix it.
150
- Return also the command that runs the tests covering the bug, the command for the whole suite, and how to start the app for end-to-end tests. After this step the tests that cover the bug are locked: the fix must pass them and nobody may change them.`,
158
+ Return also the command that runs the tests covering the bug, the command for the whole suite, and how to start the app for end-to-end tests${BROWSER ? '' : ' (browser tests will not run, so leave app.start, app.url and app.notes empty)'}. After this step the tests that cover the bug are locked: the fix must pass them and nobody may change them.${NO_BROWSER}`,
151
159
  { label: 'developer:investigate', phase: 'Investigate', agentType: 'levi-developer', schema: INVESTIGATE },
152
160
  )
153
161
  for (let i = 1; ; i++) {
@@ -159,7 +167,7 @@ Return also the command that runs the tests covering the bug, the command for th
159
167
  if (red && red.exitCode !== 0) return { ...found, red: red.summary }
160
168
  if (i >= MAX_RED) return { stop: 'blocked', detail: `after ${MAX_RED} tries, no test fails on the buggy code` }
161
169
  found = await agent(
162
- `${CONTEXT}\n\nThe tests you named (${found.bugTests.join(', ')}) all pass with \`${found.testCommand}\` on the buggy code, so they do not catch the bug. Write or correct the tests so that they fail because of this bug, then return your investigation again, updating ${INVESTIGATION}. Do not fix the bug yet.`,
170
+ `${CONTEXT}\n\nThe tests you named (${found.bugTests.join(', ')}) all pass with \`${found.testCommand}\` on the buggy code, so they do not catch the bug. Write or correct the tests so that they fail because of this bug, then return your investigation again, updating ${INVESTIGATION}. Do not fix the bug yet.${NO_BROWSER}`,
163
171
  { label: `developer:red-${i}`, phase: 'Investigate', agentType: 'levi-developer', schema: INVESTIGATE },
164
172
  )
165
173
  }
@@ -288,7 +296,7 @@ ${output}`,
288
296
  )
289
297
  }
290
298
 
291
- // ---- Fix: fix, tests, review, E2E, until the review approves and every scenario passes ----
299
+ // ---- Fix: fix, tests, review, E2E when browser tests are on, until the review approves and every scenario passes ----
292
300
 
293
301
  phase('Fix')
294
302
  const gate = () =>
@@ -343,48 +351,59 @@ Check that the fix removes the root cause rather than the symptom, everywhere it
343
351
  continue
344
352
  }
345
353
 
346
- // The review approved: QA runs its scenarios end to end.
354
+ // The review approved. QA must have finished the test cases, with browser tests on or off.
347
355
  if (!scenarios) {
348
356
  scenarios = await scenariosReady
349
357
  if (!scenarios) return { status: 'blocked', stage: 'scenarios', detail: 'QA did not finish the scenarios' }
350
358
  if (scenarios.stop === 'questions') return { status: 'questions', stage: 'scenarios', questions: scenarios.questions }
351
359
  if (scenarios.stop) return { status: 'blocked', stage: 'scenarios', detail: scenarios.detail }
352
360
  }
361
+ const caseIds = Array.from({ length: scenarios.scenarioCount }, (_, n) => `TC-${FEATURE_ID}-${String(n + 1).padStart(3, '0')}`)
362
+ const finish = (notRun) => ({
363
+ status: 'done',
364
+ rounds: round,
365
+ rootCause: inv.rootCause,
366
+ tests: inv.bugTests,
367
+ wroteTests: inv.wroteTests,
368
+ testCommand: inv.testCommand,
369
+ scenarios: { files: SCENARIO_FILES, count: scenarios.scenarioCount },
370
+ browserTests: BROWSER,
371
+ browserScope: BROWSER_SCOPE || undefined,
372
+ notRun,
373
+ review: review.summary,
374
+ suggestions: review.findings.filter((f) => f.severity === 'suggestion'),
375
+ })
376
+ // Changes to the test cases by anyone but QA are undone before they are used; QA's own results are kept after.
377
+ const restored = await restoreScenarios()
378
+ if (restored && restored.exitCode !== 0) log('the test cases had been changed outside QA and were restored')
379
+ if (!BROWSER) return finish(caseIds)
380
+
381
+ // Browser tests on: QA runs its scenarios end to end.
353
382
  const e2e = (note) =>
354
383
  agent(
355
384
  `${CONTEXT}
356
385
 
357
- The fix of this bug was approved in review. Run every test case in ${SCENARIOS} (there are ${scenarios.scenarioCount}) against the running app and record the results, following your test case guide, ${TEST_GUIDE} ("Recording results"), with the cases file ${CASES} and the output base ${TEST_BASE}. Run them ${
386
+ The fix of this bug was approved in review. Run ${
387
+ BROWSER_SCOPE
388
+ ? `only the test cases in ${SCENARIOS} that the user chose with these words: "${BROWSER_SCOPE}". List the IDs of the others in skipped and do not run them`
389
+ : `every test case in ${SCENARIOS} (there are ${scenarios.scenarioCount})`
390
+ } against the running app and record the results, following your test case guide, ${TEST_GUIDE} ("Recording results"), with the cases file ${CASES} and the output base ${TEST_BASE}. Run them ${
358
391
  inv.hasUi ? "in a headless browser: the project's E2E runner (such as Playwright) or a browser tool you have" : 'through its API or CLI'
359
392
  }. Start the app with \`${inv.app.start}\` (${inv.app.url}; ${inv.app.notes}) and stop it when you are done.
360
- Change no application code. Return the result of every case, by its ID.${note ? `\n\n${note}` : ''}`,
393
+ Change no application code. Return the result of every case you ran, by its ID.${note ? `\n\n${note}` : ''}`,
361
394
  { label: `qa:e2e-${round}`, phase: 'Fix', agentType: 'levi-qa', schema: E2E },
362
395
  )
363
- // Changes to the test cases by anyone but QA are undone before QA runs them; QA's own results are kept after.
364
- const restored = await restoreScenarios()
365
- if (restored && restored.exitCode !== 0) log('the test cases had been changed outside QA and were restored')
366
396
  const run = await e2e()
367
397
  if (!run) return { status: 'blocked', stage: 'e2e', detail: 'the E2E run did not complete' }
368
398
  await snapshotScenarios()
399
+ const skipped = new Set(BROWSER_SCOPE ? (run.skipped || []).filter((id) => caseIds.includes(id)) : [])
369
400
  const failing = []
370
- for (let n = 1; n <= scenarios.scenarioCount; n++) {
371
- const id = `TC-${FEATURE_ID}-${String(n).padStart(3, '0')}`
401
+ for (const id of caseIds) {
402
+ if (skipped.has(id)) continue
372
403
  const r = run.results.find((x) => x.id === id)
373
404
  if (!r || r.result !== 'PASS') failing.push(`${id}: ${r ? r.evidence : 'not run'}`)
374
405
  }
375
- if (!failing.length) {
376
- return {
377
- status: 'done',
378
- rounds: round,
379
- rootCause: inv.rootCause,
380
- tests: inv.bugTests,
381
- wroteTests: inv.wroteTests,
382
- testCommand: inv.testCommand,
383
- scenarios: { files: SCENARIO_FILES, count: scenarios.scenarioCount },
384
- review: review.summary,
385
- suggestions: review.findings.filter((f) => f.severity === 'suggestion'),
386
- }
387
- }
406
+ if (!failing.length) return finish([...skipped])
388
407
  last = { stage: 'e2e', failing }
389
408
  todo = `QA ran the test cases in ${SCENARIOS} end to end after the review, and these failed. Fix the code so that they pass:\n${failing.join('\n')}`
390
409
  }
@@ -55,7 +55,7 @@ A feature is one spec file, or one folder of spec files, under `docs/specs/` (se
55
55
  - *`docs/tests/<base>.md` or `.xlsx` already exists:* replace it, or write a new version with a date suffix, `<base>-YYYYMMDD` (today's date; if that exists too, add `-2`, `-3`, ...).
56
56
 
57
57
  In the same message, before the questions, tell the user every missing spec. If no feature is left to generate, say so and stop. Skip the questions when none applies.
58
- 4. **Analyze.** Call `levi-qa` once per feature (in parallel when the tool allows), with this prompt filled in:
58
+ 4. **Analyze.** Call `levi-qa`, with model `opus` and effort `high`, once per feature (in parallel when the tool allows), with this prompt filled in:
59
59
 
60
60
  ```text
61
61
  Analysis pass for feature <FeatureID>: <feature name or slug>.
@@ -69,7 +69,7 @@ A feature is one spec file, or one folder of spec files, under `docs/specs/` (se
69
69
  ```
70
70
 
71
71
  5. **Report what is missing, up front.** Before any case is written, tell the user in one message, per feature: `Generate: no` with what the spec lacks (that feature is skipped), and for the others the Missing line and the number of ambiguities found. Then go on; this is information, not a question. If every feature is `Generate: no`, delete the scratch folder and stop.
72
- 6. **Generate.** For every feature with `Generate: yes`, call `levi-qa` (in parallel when the tool allows):
72
+ 6. **Generate.** For every feature with `Generate: yes`, call `levi-qa`, with model `opus` and effort `high` (in parallel when the tool allows):
73
73
 
74
74
  ```text
75
75
  Generation pass for feature <FeatureID>: <feature name or slug>.
@@ -85,7 +85,7 @@ A feature is one spec file, or one folder of spec files, under `docs/specs/` (se
85
85
  Report the case count and every ambiguity that remains.
86
86
  ```
87
87
 
88
- 7. **Verify.** For each feature, run `node <this skill's folder>/scripts/render-test-cases.mjs check docs/levi/test-cases/<FeatureID>.json` and check that `docs/tests/<base>.md` and `docs/tests/<base>.xlsx` exist. If the check fails or a file is missing, send QA the errors once to fix and render again. If it still fails, report the feature as not done, with the errors.
88
+ 7. **Verify.** For each feature, run `node <this skill's folder>/scripts/render-test-cases.mjs check docs/levi/test-cases/<FeatureID>.json` and check that `docs/tests/<base>.md` and `docs/tests/<base>.xlsx` exist. If the check fails or a file is missing, send QA the errors once to fix and render again (again with model `opus` and effort `high`). If it still fails, report the feature as not done, with the errors.
89
89
  8. **Clean up.** Delete `docs/levi/test-cases/`, and `docs/levi` if that is empty. Delete only after step 7.
90
90
  9. **Report.** A short summary, in the language of the request:
91
91
  - per feature: the number of cases (by priority), the two file paths, and the spec it came from;
@@ -94,4 +94,4 @@ A feature is one spec file, or one folder of spec files, under `docs/specs/` (se
94
94
 
95
95
  If QA was BLOCKED or needed context, say what it needs.
96
96
 
97
- Without a parallel subagent feature, run the QA calls of steps 4 and 6 one after another; the steps are the same.
97
+ Every call to `levi-qa` here writes or changes test cases, so all of them use model `opus` and effort `high`. Without a parallel subagent feature, run the QA calls of steps 4 and 6 one after another; the steps are the same.
@@ -164,7 +164,7 @@ Never change an expected result to match what the product does. When you think t
164
164
 
165
165
  ## Recording results
166
166
 
167
- When you run the cases (end to end, in a headless browser through the project's E2E runner or a browser tool, or through the API or CLI when there is no UI):
167
+ Run the cases only when the prompt asks you to: browser tests are optional, and when the user turned them off the cases stay without a result. When you run them (end to end, in a headless browser through the project's E2E runner or a browser tool, or through the API or CLI when there is no UI):
168
168
 
169
169
  1. Follow each case's preconditions and steps as written, and compare with its expected result.
170
170
  2. In the cases file, give each case you ran `"status": "PASS"` or `"status": "FAIL"`, and `"evidence"`: what you observed (for FAIL, the actual result against the expected one, and the error). A case you could not run is FAIL, with the reason: untested is not passed.