agjan 0.0.10 → 0.0.11

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.
Files changed (31) hide show
  1. package/docs/guide.md +39 -2
  2. package/kit/domains/btp/domain.json +4 -4
  3. package/kit/skills/agjan-build/SKILL.md +10 -6
  4. package/kit/skills/agjan-design/SKILL.md +36 -4
  5. package/kit/skills/agjan-fix/SKILL.md +11 -4
  6. package/kit/skills/agjan-map/SKILL.md +11 -4
  7. package/kit/skills/agjan-spec/SKILL.md +11 -4
  8. package/kit/skills/agjan-verify/SKILL.md +26 -6
  9. package/kit/skills/cap-developer/SKILL.md +10 -2
  10. package/kit/skills/cap-developer/references/handlers.md +11 -9
  11. package/kit/skills/cap-developer/references/project-setup.md +21 -8
  12. package/kit/skills/cap-developer/references/testing.md +38 -14
  13. package/kit/skills/cap-developer/references/typescript.md +143 -0
  14. package/kit/skills/cap-developer/references/validation-security.md +26 -8
  15. package/kit/skills/fiori-developer/SKILL.md +20 -5
  16. package/kit/skills/fiori-developer/references/app-setup.md +91 -16
  17. package/kit/skills/fiori-developer/references/elements.md +19 -5
  18. package/kit/skills/fiori-developer/references/freestyle-ts.md +5 -1
  19. package/kit/skills/fiori-developer/references/testing.md +109 -15
  20. package/kit/templates/agents-block.md +4 -0
  21. package/package.json +1 -1
  22. package/src/browser.mjs +49 -0
  23. package/src/cli.mjs +14 -4
  24. package/src/commands/branch.mjs +50 -15
  25. package/src/commands/check.mjs +17 -6
  26. package/src/commands/gates.mjs +12 -9
  27. package/src/commands/review.mjs +69 -4
  28. package/src/commands/setup.mjs +12 -2
  29. package/src/commands/status.mjs +13 -11
  30. package/src/commands/ui-test.mjs +38 -0
  31. package/src/review.mjs +9 -6
@@ -7,7 +7,7 @@ import { fixRules, freshReview } from '../fix.mjs';
7
7
  import { projectProblems } from '../baseline.mjs';
8
8
  import { readFix } from './fix.mjs';
9
9
  import { fixAttempts, reviewerFor, roundLimit, roundState } from '../review-policy.mjs';
10
- import { mark, markLine, pad, tone } from '../ui.mjs';
10
+ import { blink, mark, markLine, pad, tone } from '../ui.mjs';
11
11
  import { acTestFiles } from '../tests-map.mjs';
12
12
  import { acResults, loadResults } from '../test-results.mjs';
13
13
  import { runChecks } from './check.mjs';
@@ -126,7 +126,7 @@ function describeRecordOnBase(ctx, unit) {
126
126
  * Colored with the agjan mark on a terminal; the same content as plain text for agents,
127
127
  * who end /agjan-verify with it.
128
128
  */
129
- function completion(ctx, feature, progress) {
129
+ async function completion(ctx, feature, progress) {
130
130
  const s = ctx.style;
131
131
  const areaNames = [...new Set(progress.tasks.map((t) => t.areaName))];
132
132
  const automated = feature.spec.parsed.acs.filter((ac) => ac.verification !== 'manual');
@@ -148,7 +148,9 @@ function completion(ctx, feature, progress) {
148
148
  ctx.out();
149
149
  if (s.brand) {
150
150
  const stars = `${s.teal('✦')} ${s.violet('✦')} ${s.teal('✦')}`;
151
- for (const line of mark(s, ctx.kit, `${stars} ${s.bold(`${feature.key} is done`)} ${stars}`, `${feature.slug} · development finished and verified`)) ctx.out(line);
151
+ const logo = mark(s, ctx.kit, `${stars} ${s.bold(`${feature.key} is done`)} ${stars}`, `${feature.slug} · development finished and verified`);
152
+ for (const line of logo) ctx.out(line);
153
+ await blink(ctx, logo);
152
154
  } else {
153
155
  ctx.out(`✔ ${feature.key} is done: development finished and verified (${feature.slug})`);
154
156
  }
@@ -158,7 +160,7 @@ function completion(ctx, feature, progress) {
158
160
  for (const step of steps) ctx.out(` ${s.violet('▸')} ${step}`);
159
161
  }
160
162
 
161
- function describe(ctx, feature, onBase = false) {
163
+ async function describe(ctx, feature, onBase = false) {
162
164
  if (feature.kind !== 'feature') return describeRecord(ctx, feature, onBase);
163
165
  if (onBase) return describeOnBase(ctx, feature);
164
166
  heading(ctx, feature, `stage: ${ctx.style.magenta(feature.stage)}`);
@@ -187,7 +189,7 @@ function describe(ctx, feature, onBase = false) {
187
189
  for (const d of progress.due) row(ctx, 'due', ctx.style.yellow(`review ${d.step} (${d.reason})`));
188
190
  row(ctx, 'next', nextInBuild(ctx, feature, progress).replace('<KEY>', feature.key));
189
191
  const verify = verifyState(ctx.root, ctx.config, feature);
190
- if (progress.complete && progress.due.length === 0 && verify.state === 'current') completion(ctx, feature, progress);
192
+ if (progress.complete && progress.due.length === 0 && verify.state === 'current') await completion(ctx, feature, progress);
191
193
  } else {
192
194
  // Spec and Design: either the gate is ready for the human, or what blocks it.
193
195
  const gate = pendingGate(feature);
@@ -208,11 +210,11 @@ function describe(ctx, feature, onBase = false) {
208
210
  * agjan status --done [--feature <slug>]: only the completion block of a verified feature,
209
211
  * for the agent's final message (exit 1 with the next step while it is not done).
210
212
  */
211
- function done(ctx, slug) {
213
+ async function done(ctx, slug) {
212
214
  const feature = loadFeature(ctx.root, slug);
213
215
  const progress = feature.kind === 'feature' && feature.stage === 'build' ? buildProgress(ctx.root, ctx.config, feature) : null;
214
216
  if (progress?.complete && progress.due.length === 0 && verifyState(ctx.root, ctx.config, feature).state === 'current') {
215
- completion(ctx, feature, progress);
217
+ await completion(ctx, feature, progress);
216
218
  return 0;
217
219
  }
218
220
  ctx.out(`${feature.key} is not done yet: ${progress ? nextInBuild(ctx, feature, progress).replace('<KEY>', feature.key) : `stage ${feature.stage}`}`);
@@ -220,7 +222,7 @@ function done(ctx, slug) {
220
222
  }
221
223
 
222
224
  /** agjan status [--feature <slug> | --all | --done] */
223
- export function run(ctx, argv) {
225
+ export async function run(ctx, argv) {
224
226
  const { values } = parseArgs({ args: argv, options: { feature: { type: 'string' }, all: { type: 'boolean' }, done: { type: 'boolean' } } });
225
227
  const root = ctx.root;
226
228
  if (values.done) return done(ctx, selectFeature(root, ctx.config, values.feature));
@@ -240,9 +242,9 @@ export function run(ctx, argv) {
240
242
  return 0;
241
243
  }
242
244
  const changed = new Set(changedFeatures(root, ctx.config));
243
- slugs.forEach((slug, i) => {
245
+ for (const [i, slug] of slugs.entries()) {
244
246
  if (i > 0) ctx.out();
245
- describe(ctx, loadFeature(root, slug), !changed.has(slug));
246
- });
247
+ await describe(ctx, loadFeature(root, slug), !changed.has(slug));
248
+ }
247
249
  return 0;
248
250
  }
@@ -0,0 +1,38 @@
1
+ import { spawnSync } from 'node:child_process';
2
+ import { parseArgs } from 'node:util';
3
+ import { UsageError } from '../errors.mjs';
4
+ import { UI_SCRIPT, hasUiTests, probeBrowser } from '../browser.mjs';
5
+
6
+ /**
7
+ * agjan ui-test [--require]: runs the project's UI tests (`npm run test:ui`, Playwright)
8
+ * when Chromium can start here. Where it cannot, it says why and how to enable them, and
9
+ * exits 0: UI tests are optional (design decision 75). --require makes a skip exit 1
10
+ * (for a CI job that installs the browser). Exit code 1 when the tests fail.
11
+ */
12
+ export function run(ctx, argv) {
13
+ const { values, positionals } = parseArgs({ args: argv, allowPositionals: true, options: { require: { type: 'boolean' } } });
14
+ if (positionals.length) throw new UsageError('usage: agjan ui-test [--require]');
15
+ const s = ctx.style;
16
+ const root = ctx.root;
17
+ if (!hasUiTests(root)) {
18
+ ctx.out(s.gray(`no UI tests: package.json has no ${UI_SCRIPT} script (the fiori-developer skill sets them up)`));
19
+ return values.require ? 1 : 0;
20
+ }
21
+ const browser = probeBrowser(root);
22
+ if (!browser.ready) {
23
+ ctx.out(`${s.bold('ui tests')} ${s.yellow('skipped')}: ${browser.reason}`);
24
+ ctx.out(` enable: ${browser.enable}`);
25
+ ctx.out(' The UI ACs were not tested in a browser: name them to the user, who tries them by hand.');
26
+ return values.require ? 1 : 0;
27
+ }
28
+ ctx.out(`${s.bold('ui tests')}: ${s.gray(`npm run ${UI_SCRIPT}`)}`);
29
+ const result = spawnSync(`npm run ${UI_SCRIPT}`, { cwd: root, shell: true, encoding: 'utf8', timeout: 1_800_000, maxBuffer: 64 * 1024 * 1024 });
30
+ const output = `${result.stdout ?? ''}${result.stderr ?? ''}`.trim();
31
+ if (output) ctx.out(output);
32
+ if (result.status === 0) {
33
+ ctx.out(` ${s.green('ok')}`);
34
+ return 0;
35
+ }
36
+ ctx.out(` ${s.red(result.status === null ? 'could not run (stopped)' : `failed (exit code ${result.status})`)}`);
37
+ return 1;
38
+ }
package/src/review.mjs CHANGED
@@ -138,12 +138,12 @@ function openFindings(feature, steps) {
138
138
 
139
139
  const CHECKLISTS = {
140
140
  spec: 'No unrequested technical decisions. Technical questions listed under Open technical questions are expected and are not decisions: never ask to remove that section; Design answers them. Every AC testable and complete; an AC without a Verification line is automated, which is the default and not a finding; flag only ACs that cannot be tested automatically but are not marked manual. Non-functional and authorization requirements considered. Scope consistent.',
141
- 'design:light': 'The spec checks, plus: light mode is justified (nothing new: no new service, application, BTP service, authorization or deployment change). Tasks: paths plausible and including where the tests of their ACs go, every AC covered.',
142
- design: 'Every AC covered by tasks. Areas and app types justified with alternatives. Open technical questions answered. Every rule of the spec\'s Authorization section has a decision on how it is enforced. Every task\'s paths include where the tests of its ACs go (tests of Fiori annotations usually live in the CAP tests). Nothing beyond the spec.',
143
- build: 'Each covered AC is met by the diff. Tests exist and carry the AC id in their names. Project conventions. The spec\'s Authorization section, rule by rule: each role and permission is enforced in the code (for example @requires or @restrict on every entity and operation it covers; anything without them is open to every user, anonymous requests included) and covered by tests, including a negative test for a user without the role and for an anonymous request. Security basics (authorization, input validation, no secrets; test or mocked users and other development settings only in a development profile, never active in production). Scope is checked by agjan: a file under the allowed paths (task, implicit or amended) is in scope; do not report it as out of scope.',
141
+ 'design:light': 'The spec checks, plus: light mode is justified (nothing new: no new service, application, BTP service, authorization or deployment change). Tasks: paths plausible and including where the tests of their ACs go, every AC covered. In a Fiori elements app, creating or editing records needs a draft-enabled entity.',
142
+ design: 'Every AC covered by tasks. Areas and app types justified with alternatives. Open technical questions answered. Every rule of the spec\'s Authorization section has a decision on how it is enforced. Every task\'s paths include where the tests of its ACs go (tests of Fiori annotations usually live in the CAP tests); a task covers an AC only if its paths include every file needed to implement and test it. The chosen service shape supports every interaction the ACs describe in the UI: in a Fiori elements app, creating or editing records needs a draft-enabled entity (@odata.draft.enabled), so "no draft" for such an app is a blocker. Nothing beyond the spec.',
143
+ build: 'Each covered AC is met by the diff. Tests exist and carry the AC id in their names. An AC that a user does on a page of a Fiori app (create a record, choose an action) has a UI test (Playwright, test/ui) besides the service tests; UI tests that agjan ui-test skipped because no browser can start here are not a finding. Project conventions. The spec\'s Authorization section, rule by rule: each role and permission is enforced in the code (for example @requires or @restrict on every entity and operation it covers; anything without them is open to every user, anonymous requests included) and covered by tests, including a negative test for a user without the role and for an anonymous request, and for every where condition a test with a user who has the role but whom the condition excludes. The service has a service-level @requires, so nothing it exposes (code lists, auto-exposed entities) is open. Security basics (authorization, input validation, no secrets; test or mocked users and other development settings only in a development profile, never active in production). Scope is checked by agjan: a file under the allowed paths (task, implicit or amended) is in scope; do not report it as out of scope.',
144
144
  fix: 'The change does exactly what the fix description says and nothing else. It is correct and complete. A test covers it where practical. No hidden scope: anything that changes behaviour beyond the description, or needs a business decision, is a blocker (it belongs in /agjan-spec).',
145
145
  map: 'Every claim in project.md is traceable to the files it points to. Services, applications and BTP services are complete. The do-not-touch list is plausible and uses real paths. Short: one to two pages, pointers instead of copies.',
146
- verify: 'Cross-task consistency. Every AC covered by a passing test or marked manual. The spec\'s Authorization section, rule by rule: each role and permission is enforced in the code (for example @requires or @restrict on every entity and operation it covers; anything without them is open to every user, anonymous requests included) and covered by tests, including a negative test for a user without the role and for an anonymous request. Scope is checked by agjan: a file under the allowed paths (task, implicit or amended) is in scope; do not report it as out of scope. The baseline (project.md) updated if a service, application or BTP service was added, and its section "Run locally" (start command, app URLs, test users and roles) matches the change. Do not re-review each task.',
146
+ verify: 'Cross-task consistency. Every AC covered by a passing test or marked manual. UI tests that agjan ui-test skipped because no browser can start here are not a finding: the final message names those ACs for the human. When the project records no test results (no results file in the context), judge coverage by the tests that carry the AC ids: missing recorded results is a project setting for the human, not a finding. The spec\'s Authorization section, rule by rule: each role and permission is enforced in the code (for example @requires or @restrict on every entity and operation it covers; anything without them is open to every user, anonymous requests included) and covered by tests, including a negative test for a user without the role and for an anonymous request. Scope is checked by agjan: a file under the allowed paths (task, implicit or amended) is in scope; do not report it as out of scope. The baseline (project.md) updated if a service, application or BTP service was added, and its section "Run locally" (start command, app URLs, test users and roles) matches the change. Do not re-review each task.',
147
147
  };
148
148
 
149
149
  /**
@@ -224,11 +224,14 @@ export function buildContextText(root, config, feature, parsed) {
224
224
  const loaded = loadResults(root, config, areaNames);
225
225
  const results = loaded.files.length ? acResults(loaded, feature.key) : null;
226
226
  const coverage = feature.spec.parsed.acs
227
- .map((ac) => `| ${ac.id} | ${ac.verification} | ${[...(tests.get(ac.id) ?? [])].join(', ') || '-'} | ${results ? resultLabel(results.get(ac.id)) : 'no results'} |`)
227
+ .map((ac) => `| ${ac.id} | ${ac.verification} | ${[...(tests.get(ac.id) ?? [])].join(', ') || '-'} | ${results ? resultLabel(results.get(ac.id)) : 'not recorded'} |`)
228
228
  .join('\n');
229
+ const unrecorded = results
230
+ ? ''
231
+ : '\n\nThis project records no test results (no `verify.<area>.results` in agjan.config.json, a setting for the human). Coverage here means a test names the AC; missing results are not a finding.';
229
232
  const changed = changedFiles(root, base).filter((f) => !scriptOwned(feature.slug).has(f) && !f.startsWith('.agjan/'));
230
233
  parts.push(section('Acceptance criteria', acsText(feature)));
231
- parts.push(section('AC coverage (test files mentioning the AC id, and test results)', `| AC | verification | test files | result |\n|---|---|---|---|\n${coverage}`));
234
+ parts.push(section('AC coverage (test files mentioning the AC id, and test results)', `| AC | verification | test files | result |\n|---|---|---|---|\n${coverage}${unrecorded}`));
232
235
  parts.push(section(docPath(feature, 'design.md'), fence(feature.design.text, 'md')));
233
236
  parts.push(section(docPath(feature, 'tasks.md'), fence(feature.tasks.text, 'md')));
234
237
  parts.push(section('Allowed paths (scope, enforced by agjan check)', scopeText(scopeOf(config, feature, feature.tasks.parsed.tasks))));