badday 0.1.1 → 0.1.2

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 (3) hide show
  1. package/README.md +14 -9
  2. package/dist/cli.js +76 -39
  3. package/package.json +5 -3
package/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # badday
2
2
 
3
+ [![test](https://github.com/umar5678/badday/actions/workflows/test.yml/badge.svg)](https://github.com/umar5678/badday/actions/workflows/test.yml) [![npm](https://img.shields.io/npm/v/badday)](https://www.npmjs.com/package/badday)
4
+
3
5
  Give your backend a bad day before production does.
4
6
 
5
7
  Find out if your backend double-charges, leaks another user's data or falls over on a bad request, before a customer does.
@@ -16,6 +18,10 @@ BROKEN A customer who double-clicks "Pay" is charged twice.
16
18
  20 orders.
17
19
  ```
18
20
 
21
+ Each run also writes `badday-report.html`, one file with every request, every response and a fix prompt for each failure. This is the report of `npx badday demo`:
22
+
23
+ ![The badday report of the demo shop: 31 promises broken, 0 kept, one card per pack and one card per broken promise](https://raw.githubusercontent.com/umar5678/badday/main/docs/report.png)
24
+
19
25
  ## Hand it to your coding agent
20
26
 
21
27
  Most people never type a badday command. Start your backend, then paste this into Claude Code, Cursor or any other coding agent:
@@ -23,12 +29,12 @@ Most people never type a badday command. Start your backend, then paste this int
23
29
  ```
24
30
  Run `npx badday init --agent` and follow the brief it prints. Write badday.config.json
25
31
  for this backend, run `npx badday validate` until it reports no problem, then run
26
- `npx badday run --json`. For each check that fails, read its evidence and fixPrompt and
27
- fix the backend, not the config. Run it again until nothing fails, then tell me which
28
- checks were not tested and what each one needs.
32
+ `npx badday run --json` once. Show me the path of the report, the checks that failed,
33
+ and the checks that were not tested with what each one needs. Do not change any code
34
+ yet. I will tell you which failures to fix.
29
35
  ```
30
36
 
31
- The agent reads your routes and auth, writes the config and fixes what breaks. badday refuses any host that is not on your machine, so the agent cannot point it at production by accident.
37
+ The agent reads your routes and auth, writes the config, runs the checks and shows you what broke. It changes your code only for the failures you pick, and fixes the backend, never the config. badday refuses any host that is not on your machine, so the agent cannot point it at production by accident.
32
38
 
33
39
  If you use Claude Code, `npx badday init --skill` writes a skill to `.claude/skills/badday/`. After that, "test this backend with badday" is enough.
34
40
 
@@ -95,7 +101,7 @@ Each failure comes with a fix prompt: a paragraph that names the defect, the evi
95
101
  npx badday init --agent
96
102
  ```
97
103
 
98
- This prints a brief with the loop, the place to look for routes and auth, every config field and the shape of the output. The loop is short: write `badday.config.json`, run `npx badday validate` until it reports no problem, then run `npx badday run --json`. `validate` names the path, the problem and the fix for each error.
104
+ This prints a brief with the loop, the place to look for routes and auth, every config field and the shape of the output. The loop is short: write `badday.config.json`, run `npx badday validate` until it reports no problem, run `npx badday run --json`, show the person the report, and fix only the failures the person picks. `validate` names the path, the problem and the fix for each error.
99
105
 
100
106
  `npx badday init --skill` writes the same procedure as a Claude Code skill to `.claude/skills/badday/SKILL.md`, so later sessions find it without a prompt.
101
107
 
@@ -185,11 +191,12 @@ npx badday run # every check
185
191
  npx badday run --only replay,cross-user-read
186
192
  npx badday run --skip webhooks
187
193
  npx badday run --detail # print the requests of each failure
188
- npx badday run --json # one JSON document, for CI and agents
194
+ npx badday run --json # verdicts, facts and fix prompts, for agents
195
+ npx badday run --json-full # the same with every request and response, for CI
189
196
  npx badday init --from openapi.json # draft a config from an OpenAPI file or URL
190
197
  ```
191
198
 
192
- `run` also writes `badday-report.html`, one self-contained file with every request and response. `--no-html` turns that off.
199
+ `run` also writes `badday-report.html`, one self-contained file with every request and response, and `--json` too. The JSON names the file in its `report` field. `--json` leaves the requests and responses out, so an agent can read the result in one go. They stay in the report and in `--json-full`. `--html <file>` writes it somewhere else, and `--no-html` turns it off.
193
200
 
194
201
  Exit code 0 means no check failed, 1 means a check failed, and 2 means the config or the target was not usable.
195
202
 
@@ -236,8 +243,6 @@ Every config below was written by `badday record` from a scripted user session.
236
243
 
237
244
  The other 24 checks report "not tested" there. VAmPI has no idempotency key, no webhook, no update or delete for books and no paging, and its other planted defects, such as SQL injection, are outside what badday tests. That is one catch, and the one the two instances differ in.
238
245
 
239
- badday also ran this way on five projects that are not vulnerable on purpose. Their results go to the maintainers first and are not listed here.
240
-
241
246
  ## Limits of version 0.1
242
247
 
243
248
  - `badday record` learns resources that have a create route and at least one more route on the same path. It does not learn webhooks, and it stores the tokens it saw, which expire.
package/dist/cli.js CHANGED
@@ -901,27 +901,27 @@ var keyCrossUser = {
901
901
  const req = keyed(resource, createReq(ctx, owner), ctx.marker + "-shared");
902
902
  const mine = await client.send({ ...req });
903
903
  const myId = createdId(ctx, mine);
904
- mine.note = myId ? `${owner} created ${myId}` : "the first request";
904
+ mine.note = myId ? `${cap(owner)} created ${myId}` : "the first request";
905
905
  const theirs = await client.send({ ...req, actor: other });
906
906
  const theirId = createdId(ctx, theirs);
907
907
  const leaked = !!myId && theirId === myId;
908
- theirs.note = !ok(theirs) ? `refused with ${theirs.response?.status ?? "no answer"}` : leaked ? `${other} got ${myId}, the ${singular2} of ${owner}` : `${other} created ${theirId}, their own ${singular2}`;
908
+ theirs.note = !ok(theirs) ? `refused with ${theirs.response?.status ?? "no answer"}` : leaked ? `${cap(other)} got ${myId}, the ${singular2} of ${cap(owner)}` : `${cap(other)} created ${theirId}, their own ${singular2}`;
909
909
  await newRecords(ctx, owner, before, [myId]);
910
910
  if (theirId && !leaked) ctx.track(other, theirId);
911
911
  const story = `${cap(owner)} sent one ${singular2} with a key. ${cap(other)} sent the same request with the same key.`;
912
- const facts = [{ label: `What ${other} gets back`, expected: `${an(singular2)} of their own, or a refusal`, actual: leaked ? `${myId}, which belongs to ${owner}` : theirId ?? String(theirs.response?.status ?? "no answer") }];
912
+ const facts = [{ label: `What ${cap(other)} gets back`, expected: `${an(singular2)} of their own, or a refusal`, actual: leaked ? `${myId}, which belongs to ${cap(owner)}` : theirId ?? String(theirs.response?.status ?? "no answer") }];
913
913
  if (!myId) return { verdict: "warning", facts, summary: `Your app refused the first create request with ${mine.response?.status ?? "no answer"}, so this check proves nothing.` };
914
914
  if (leaked) {
915
915
  return {
916
916
  verdict: "fail",
917
917
  facts,
918
- summary: `${story} Your app answered ${other} with the ${singular2} of ${owner}.`,
918
+ summary: `${story} Your app answered ${cap(other)} with the ${singular2} of ${cap(owner)}.`,
919
919
  fixPrompt: `My backend returns one user's saved response to a different user who sends the same idempotency key. A test created ${an(singular2)} as one user with the ${keyName(resource)}, then sent the same request and key as a second user. The second user got the first user's ${singular2} back.
920
920
 
921
921
  The key store uses the key alone as its lookup. Make the lookup the user id together with the key, with the user id taken from the verified session. Two users who send the same key must get two separate entries.`
922
922
  };
923
923
  }
924
- return { verdict: "pass", facts, summary: `${story} ${cap(other)} ${theirId ? `got a new ${singular2} of their own` : `was refused with ${theirs.response?.status ?? "no answer"}`}, and saw nothing of ${owner}.` };
924
+ return { verdict: "pass", facts, summary: `${story} ${cap(other)} ${theirId ? `got a new ${singular2} of their own` : `was refused with ${theirs.response?.status ?? "no answer"}`}, and saw nothing of ${cap(owner)}.` };
925
925
  }
926
926
  };
927
927
 
@@ -1609,20 +1609,20 @@ var cursorCrossUser = {
1609
1609
  const sent = await ctx.client.send({ actor: other, method: "GET", path: listPath(spec, params) });
1610
1610
  const rows = pageOf(sent, spec, resource.name)?.rows ?? [];
1611
1611
  const leaked = rows.map((row) => idOf(ctx, row)).filter((id2) => id2 && real.ids.includes(id2));
1612
- sent.note = leaked.length ? `${other} sends the cursor of ${owner} and gets ${leaked.join(", ")}` : `${other} sends the cursor of ${owner}, answered ${statusOf(sent)}`;
1612
+ sent.note = leaked.length ? `${cap(other)} sends the cursor of ${cap(owner)} and gets ${leaked.join(", ")}` : `${cap(other)} sends the cursor of ${cap(owner)}, answered ${statusOf(sent)}`;
1613
1613
  const story = `${cap(owner)} created 3 ${resource.name} and read a page, which came with a cursor. ${cap(other)} sent that cursor.`;
1614
- const facts = [{ label: `Records of ${owner} in the page ${other} got`, expected: "0", actual: String(leaked.length) }];
1614
+ const facts = [{ label: `Records of ${cap(owner)} in the page ${cap(other)} got`, expected: "0", actual: String(leaked.length) }];
1615
1615
  if (leaked.length) {
1616
1616
  return {
1617
1617
  verdict: "fail",
1618
1618
  facts,
1619
- summary: `${story} The page held ${leaked.length} of the ${resource.name} of ${owner}.`,
1619
+ summary: `${story} The page held ${leaked.length} of the ${resource.name} of ${cap(owner)}.`,
1620
1620
  fixPrompt: `My list route GET ${spec.path} trusts what is inside the page cursor. A test took a cursor from one user and sent it as a second user, and the page held the first user's ${resource.name}.
1621
1621
 
1622
1622
  The cursor must hold a position only, such as the last id or timestamp. Filter every page by the user id of the verified session, never by anything inside the cursor. If the cursor must carry more, sign it and reject one whose signature fails.`
1623
1623
  };
1624
1624
  }
1625
- return { verdict: "pass", facts, summary: `${story} The page held none of the ${resource.name} of ${owner}.` };
1625
+ return { verdict: "pass", facts, summary: `${story} The page held none of the ${resource.name} of ${cap(owner)}.` };
1626
1626
  }
1627
1627
  };
1628
1628
 
@@ -1936,12 +1936,12 @@ var crossUserDelete = {
1936
1936
  const remove = resource.remove;
1937
1937
  const record2 = await createOne(ctx, owner);
1938
1938
  const sent = await ctx.client.send({ actor: other, method: remove.method, path: withId(remove.path, record2.id) });
1939
- sent.note = ok(sent) ? `${other} deletes the ${resource.singular} of ${owner}` : `${other} is refused with ${statusOf(sent)}`;
1940
- const gone = resource.get ? !await readAs(ctx, owner, record2.id, `${owner} looks for it afterwards`) : false;
1939
+ sent.note = ok(sent) ? `${cap(other)} deletes the ${resource.singular} of ${cap(owner)}` : `${cap(other)} is refused with ${statusOf(sent)}`;
1940
+ const gone = resource.get ? !await readAs(ctx, owner, record2.id, `${cap(owner)} looks for it afterwards`) : false;
1941
1941
  const story = `${cap(owner)} created ${an(resource.singular)}. ${cap(other)} sent a delete for it.`;
1942
1942
  const facts = [
1943
- { label: `The answer to the delete by ${other}`, expected: "403 or 404", actual: statusOf(sent) },
1944
- ...resource.get ? [{ label: `The ${resource.singular}, when ${owner} looks for it afterwards`, expected: "still there", actual: gone ? "gone" : "still there" }] : []
1943
+ { label: `The answer to the delete by ${cap(other)}`, expected: "403 or 404", actual: statusOf(sent) },
1944
+ ...resource.get ? [{ label: `The ${resource.singular}, when ${cap(owner)} looks for it afterwards`, expected: "still there", actual: gone ? "gone" : "still there" }] : []
1945
1945
  ];
1946
1946
  if (ok(sent) || gone) {
1947
1947
  return {
@@ -1971,10 +1971,10 @@ var crossUserList = {
1971
1971
  const { resource, owner } = ctx;
1972
1972
  const other = ctx.other;
1973
1973
  const mine = await createMany(ctx, owner, COUNT);
1974
- const listed = await listAll(ctx, other, { note: `${other} reads the list` });
1974
+ const listed = await listAll(ctx, other, { note: `${cap(other)} reads the list` });
1975
1975
  const leaked = mine.filter((id2) => listed.has(id2));
1976
1976
  const story = `${cap(owner)} created ${COUNT} ${resource.name}. ${cap(other)} read the whole list.`;
1977
- const facts = [{ label: `${cap(resource.name)} of ${owner} in the list of ${other}`, expected: "0", actual: String(leaked.length) }];
1977
+ const facts = [{ label: `${cap(resource.name)} of ${cap(owner)} in the list of ${cap(other)}`, expected: "0", actual: String(leaked.length) }];
1978
1978
  if (leaked.length) {
1979
1979
  return {
1980
1980
  verdict: "fail",
@@ -2003,9 +2003,9 @@ var crossUserRead = {
2003
2003
  const other = ctx.other;
2004
2004
  const record2 = await createOne(ctx, owner);
2005
2005
  const sent = await ctx.client.send({ actor: other, method: "GET", path: withId(resource.get, record2.id) });
2006
- sent.note = ok(sent) ? `${other} reads the ${resource.singular} of ${owner}` : `${other} is refused with ${statusOf(sent)}`;
2006
+ sent.note = ok(sent) ? `${cap(other)} reads the ${resource.singular} of ${cap(owner)}` : `${cap(other)} is refused with ${statusOf(sent)}`;
2007
2007
  const story = `${cap(owner)} created ${an(resource.singular)}. ${cap(other)} asked for it by its id.`;
2008
- const facts = [{ label: `${cap(other)} reads ${an(resource.singular)} of ${owner}`, expected: "403 or 404", actual: ok(sent) ? `${statusOf(sent)}, with the ${resource.singular}` : statusOf(sent) }];
2008
+ const facts = [{ label: `${cap(other)} reads ${an(resource.singular)} of ${cap(owner)}`, expected: "403 or 404", actual: ok(sent) ? `${statusOf(sent)}, with the ${resource.singular}` : statusOf(sent) }];
2009
2009
  if (ok(sent)) {
2010
2010
  return {
2011
2011
  verdict: "fail",
@@ -2034,15 +2034,15 @@ var crossUserUpdate = {
2034
2034
  const other = ctx.other;
2035
2035
  const update = resource.update;
2036
2036
  const record2 = await createOne(ctx, owner);
2037
- const before = resource.get ? await readAs(ctx, owner, record2.id, `${owner} reads it before`) : null;
2037
+ const before = resource.get ? await readAs(ctx, owner, record2.id, `${cap(owner)} reads it before`) : null;
2038
2038
  const sent = await ctx.client.send({ actor: other, method: update.method, path: withId(update.path, record2.id), body: update.body ?? {} });
2039
- sent.note = ok(sent) ? `${other} updates the ${resource.singular} of ${owner}` : `${other} is refused with ${statusOf(sent)}`;
2040
- const after = resource.get ? await readAs(ctx, owner, record2.id, `${owner} reads it after`) : null;
2039
+ sent.note = ok(sent) ? `${cap(other)} updates the ${resource.singular} of ${cap(owner)}` : `${cap(other)} is refused with ${statusOf(sent)}`;
2040
+ const after = resource.get ? await readAs(ctx, owner, record2.id, `${cap(owner)} reads it after`) : null;
2041
2041
  const changed = !!before && JSON.stringify(before) !== JSON.stringify(after);
2042
2042
  const story = `${cap(owner)} created ${an(resource.singular)}. ${cap(other)} sent an update for it.`;
2043
2043
  const facts = [
2044
- { label: `The answer to the update by ${other}`, expected: "403 or 404", actual: statusOf(sent) },
2045
- ...before ? [{ label: `The ${resource.singular}, when ${owner} reads it afterwards`, expected: "unchanged", actual: changed ? "changed" : "unchanged" }] : []
2044
+ { label: `The answer to the update by ${cap(other)}`, expected: "403 or 404", actual: statusOf(sent) },
2045
+ ...before ? [{ label: `The ${resource.singular}, when ${cap(owner)} reads it afterwards`, expected: "unchanged", actual: changed ? "changed" : "unchanged" }] : []
2046
2046
  ];
2047
2047
  if (ok(sent) || changed) {
2048
2048
  return {
@@ -2054,7 +2054,7 @@ var crossUserUpdate = {
2054
2054
  Add the owner to the query of the update, so it matches the record by its id and by the user id of the caller. If no row matches, answer 404. Take the user id from the verified session, never from the request.`
2055
2055
  };
2056
2056
  }
2057
- return { verdict: "pass", facts, summary: `${story} Your app answered ${statusOf(sent)}${before ? `, and the ${resource.singular} was unchanged when ${owner} read it afterwards` : ""}.` };
2057
+ return { verdict: "pass", facts, summary: `${story} Your app answered ${statusOf(sent)}${before ? `, and the ${resource.singular} was unchanged when ${cap(owner)} read it afterwards` : ""}.` };
2058
2058
  }
2059
2059
  };
2060
2060
 
@@ -2116,7 +2116,7 @@ var protectedFields = {
2116
2116
  const updated = await client.send({ actor: owner, method: resource.update.method, path: withId(resource.update.path, honest.id), body: withFields(resource, resource.update.body, attack) });
2117
2117
  let doc = ok(updated) ? recordOf(ctx, updated.response.body) : null;
2118
2118
  if (resource.get) {
2119
- const read = await client.send({ actor: owner, method: "GET", path: withId(resource.get, honest.id), note: `${owner} reads the record after the update` });
2119
+ const read = await client.send({ actor: owner, method: "GET", path: withId(resource.get, honest.id), note: `${cap(owner)} reads the record after the update` });
2120
2120
  doc = ok(read) ? recordOf(ctx, read.response.body) : doc;
2121
2121
  }
2122
2122
  onUpdate = taken(doc);
@@ -2637,7 +2637,7 @@ function controlsOf(name) {
2637
2637
  }
2638
2638
 
2639
2639
  // src/engine/runner.ts
2640
- var VERSION = "0.1.1";
2640
+ var VERSION = "0.1.2";
2641
2641
  var BODY_LIMIT2 = 2e3;
2642
2642
  var PROBE_TIMEOUT_MS = 4e3;
2643
2643
  var STALL_LIMIT_MS = 9e4;
@@ -2699,7 +2699,16 @@ async function runOne({ check, resource, webhook }, model, marker, records) {
2699
2699
  };
2700
2700
  let result;
2701
2701
  try {
2702
- const outcome = await check.run(ctx);
2702
+ let outcome = await check.run(ctx);
2703
+ const limited = client.exchanges.filter((x) => x.response?.status === 429).length;
2704
+ if (outcome.verdict === "pass" && limited) {
2705
+ outcome = {
2706
+ ...outcome,
2707
+ verdict: "warning",
2708
+ title: `We could not tell ${check.question}, because your app limited our request rate.`,
2709
+ summary: `${outcome.summary} Your app answered ${limited} of these requests with 429 Too Many Requests, so a refusal here may only mean we were throttled. Raise the rate limit for the test run and run this check again.`
2710
+ };
2711
+ }
2703
2712
  const title = outcome.title ?? (outcome.verdict === "pass" ? check.promise : outcome.verdict === "fail" ? check.consequence : outcome.verdict === "warning" ? `We could not tell ${check.question}.` : `We could not test ${check.question}.`);
2704
2713
  result = {
2705
2714
  ...base,
@@ -3100,8 +3109,9 @@ h1 { font: 400 clamp(28px, 5vw, 44px)/1.15 var(--serif); letter-spacing: -0.01em
3100
3109
  h1 .fail { color: var(--fail); } h1 .pass { color: var(--pass); }
3101
3110
  h1 .warning { color: var(--warning); } h1 .not-configured { color: var(--skip); }
3102
3111
 
3103
- .tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); overflow-x: auto; }
3104
- .tabs button { background: none; border: 0; border-bottom: 2px solid transparent; padding: 9px 14px; margin-bottom: -1px; color: var(--muted); white-space: nowrap; }
3112
+ .tabs { display: flex; gap: 4px; box-shadow: inset 0 -1px var(--line); overflow-x: auto; overflow-y: hidden; scrollbar-width: none; }
3113
+ .tabs::-webkit-scrollbar { display: none; }
3114
+ .tabs button { background: none; border: 0; border-bottom: 2px solid transparent; padding: 9px 14px; color: var(--muted); white-space: nowrap; }
3105
3115
  .tabs button:hover { color: var(--ink); }
3106
3116
  .tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--ink); font-weight: 600; }
3107
3117
 
@@ -3635,7 +3645,9 @@ If a person can use the app in a browser or an API client, \`npx badday record -
3635
3645
  3. Run \`npx badday validate\`. Each problem it prints has a path, a problem and a fix. Correct the file and run the command again, until it prints no problem.
3636
3646
  4. Start the backend, if it does not run.
3637
3647
  5. Run \`npx badday run --json\`.
3638
- 6. For each check with the verdict \`fail\`, read its \`summary\`, \`evidence\` and \`fixPrompt\`. Fix the backend. Run step 5 again.
3648
+ 6. Show the person the path in \`report\`. That file is the HTML report, with every request, every response and the standards tabs. Show the title of each check with the verdict \`fail\`, and the summary of each check with the verdict \`not-configured\`.
3649
+ 7. Ask the person which failures to fix. Do not change the backend before the person answers.
3650
+ 8. For each failure that the person picks, read its \`summary\`, \`facts\` and \`fixPrompt\`. Fix the backend, not the config. Run step 5 again.
3639
3651
 
3640
3652
  ## Where to look
3641
3653
 
@@ -3679,16 +3691,16 @@ Describe the backend as it is. Read one real create response and one real list r
3679
3691
 
3680
3692
  ## The result of \`run --json\`
3681
3693
 
3682
- One JSON document on stdout. \`checks\` is a list. Each check has:
3694
+ One JSON document on stdout. It holds no requests and no responses, so you can read all of it. \`--json-full\` adds them, under \`evidence.exchanges\`, with credentials replaced by \`[redacted]\`. \`report\` is the absolute path of the HTML report that the run wrote, \`badday-report.html\` in the current folder if \`--html <file>\` is absent. \`report\` is \`null\` if you pass \`--no-html\`. \`checks\` is a list. Each check has:
3683
3695
 
3684
- - \`id\`, \`name\` and \`pack\`
3696
+ - \`id\` and \`pack\`
3685
3697
  - \`verdict\`: \`pass\`, \`fail\`, \`warning\` or \`not-configured\`
3686
3698
  - \`title\`: the result in one sentence
3687
3699
  - \`summary\`: what badday sent and what the backend did
3688
- - \`evidence.facts\`: what a correct backend does, against what this one did
3689
- - \`evidence.exchanges\`: each request and its response, with credentials replaced by \`[redacted]\`
3700
+ - \`facts\`: what a correct backend does, against what this one did
3690
3701
  - \`fixPrompt\`: on a failure, the defect and the standard remedy
3691
- - \`controls\`: the controls of HIPAA, GDPR, PCI DSS, SOC 2 and the OWASP API Top 10 that the check gives evidence for. This mapping is a draft, written by developers. It is not a compliance assessment.
3702
+
3703
+ \`counts\` gives the number of checks for each verdict. A \`warning\` means that badday could not tell. One cause is a rate limit: if the backend answers 429, raise the limit for the test run.
3692
3704
 
3693
3705
  A \`not-configured\` check did not run. Its \`summary\` says what to add to the config.
3694
3706
 
@@ -4295,7 +4307,7 @@ Run the checks with: npx badday run${opts.out ? " --config " + opts.out : ""}`);
4295
4307
  // src/cli/skill.ts
4296
4308
  import { existsSync as existsSync3, mkdirSync, writeFileSync as writeFileSync2 } from "node:fs";
4297
4309
  import { dirname, relative, resolve as resolve3 } from "node:path";
4298
- var skillText = () => true ? "---\nname: badday\ndescription: Test a live HTTP backend for broken promises with the badday CLI. Use when the user asks to check a backend for duplicate charges, replayed webhooks, cross-user data leaks or crashes on bad input, or asks to set up or run badday.\n---\n\n# badday\n\nbadday sends requests to a live backend and reports the promises that the backend broke. badday does not read the code of the backend.\n\n## Procedure\n\n1. Run `npx badday init --agent`. Read the brief it prints. The brief holds every config field.\n2. Find the routes, the authentication and two test users in the repository. Do not guess a value. If the repository does not show a value, ask the user.\n3. Write `badday.config.json` in the project root.\n4. Run `npx badday validate`. If it prints a problem, apply the fix it names and run the command again.\n5. Start the backend, if it does not run.\n6. Run `npx badday run --json`.\n7. For each check with the verdict `fail`, read `summary`, `evidence` and `fixPrompt`. Fix the backend.\n8. Run step 6 again, until no check has the verdict `fail`.\n9. Tell the user which checks have the verdict `not-configured`, and what each one needs.\n\n## Rules\n\n- A `not-configured` check did not run. Do not report it as a pass.\n- Do not change the config to make a check pass. Fix the backend.\n- Do not pass `--i-own-this-server`, unless the user tells you to.\n- The file `badday.config.json` can hold real tokens. Do not commit it, unless the user tells you to.\n- The standards tabs of the report show a draft. Do not tell the user that the backend meets a standard.\n\n## Exit codes\n\n- 0: no check failed.\n- 1: one check or more failed.\n- 2: the config or the target is not usable. The message names the fix.\n" : readFileSync3(new URL("../../agents/skill/badday/SKILL.md", import.meta.url), "utf8");
4310
+ var skillText = () => true ? "---\nname: badday\ndescription: Test a live HTTP backend for broken promises with the badday CLI. Use when the user asks to check a backend for duplicate charges, replayed webhooks, cross-user data leaks or crashes on bad input, or asks to set up or run badday.\n---\n\n# badday\n\nbadday sends requests to a live backend and reports the promises that the backend broke. badday does not read the code of the backend.\n\n## Procedure\n\n1. Run `npx badday init --agent`. Read the brief it prints. The brief holds every config field.\n2. Find the routes, the authentication and two test users in the repository. Do not guess a value. If the repository does not show a value, ask the user.\n3. Write `badday.config.json` in the project root.\n4. Run `npx badday validate`. If it prints a problem, apply the fix it names and run the command again.\n5. Start the backend, if it does not run.\n6. Run `npx badday run --json`.\n7. Give the user the path in the `report` field of the JSON. That file is the HTML report of the run.\n8. Show the user the title of each check with the verdict `fail`, and the summary of each check with the verdict `not-configured`.\n9. Ask the user which failures to fix. Do not change the backend before the user answers.\n10. For each failure that the user picks, read `summary`, `facts` and `fixPrompt`. Fix the backend.\n11. Run step 6 again. Show the user the new report.\n\n## Rules\n\n- A `not-configured` check did not run. Do not report it as a pass.\n- Do not change the config to make a check pass. Fix the backend.\n- Do not pass `--i-own-this-server`, unless the user tells you to.\n- The file `badday.config.json` can hold real tokens. Do not commit it, unless the user tells you to.\n- The standards tabs of the report show a draft. Do not tell the user that the backend meets a standard.\n\n## Exit codes\n\n- 0: no check failed.\n- 1: one check or more failed.\n- 2: the config or the target is not usable. The message names the fix.\n" : readFileSync3(new URL("../../agents/skill/badday/SKILL.md", import.meta.url), "utf8");
4299
4311
  function writeSkill(force) {
4300
4312
  const file = resolve3(".claude/skills/badday/SKILL.md");
4301
4313
  if (existsSync3(file) && !force) throw new UsageError(`${relative(process.cwd(), file)} exists. Pass --force to replace it.`);
@@ -4432,7 +4444,9 @@ Options for run and demo:
4432
4444
  --only <names> run only these checks or packs, separated by commas
4433
4445
  --skip <names> leave these checks or packs out
4434
4446
  --detail print the requests and responses of each failure
4435
- --json print the result as one JSON document
4447
+ --json print the result as one compact JSON document: each verdict, its facts and
4448
+ its fix prompt. The requests and responses stay in the HTML report
4449
+ --json-full print the full result, with every request and response, for CI and archives
4436
4450
  --html <file> where to write the HTML report. badday-report.html if absent
4437
4451
  --no-html write no HTML report
4438
4452
  --i-own-this-server <hostname>
@@ -4442,6 +4456,7 @@ Options for run and demo:
4442
4456
  Exit codes: 0 no check failed, 1 a check failed, 2 the config or the target is not usable.
4443
4457
  `;
4444
4458
  var VALUE_FLAGS = ["--config", "--only", "--skip", "--html", "--from", "--i-own-this-server", "--base-url", "--target", "--port", "--har", "--out"];
4459
+ var SWITCHES = ["--agent", "--detail", "--fixed", "--force", "--help", "--json", "--json-full", "--no-html", "--no-probe", "--skill", "--version"];
4445
4460
  function parse2(argv) {
4446
4461
  const flags = {};
4447
4462
  let command;
@@ -4453,6 +4468,7 @@ function parse2(argv) {
4453
4468
  continue;
4454
4469
  }
4455
4470
  const [name, inline] = arg.split(/=(.*)/s);
4471
+ if (!VALUE_FLAGS.includes(name) && !SWITCHES.includes(name)) throw new UsageError(`badday has no option "${name}". Run badday help for the options.`);
4456
4472
  if (inline !== void 0) flags[name] = inline;
4457
4473
  else if (VALUE_FLAGS.includes(name) && argv[i + 1] !== void 0 && !argv[i + 1].startsWith("--")) flags[name] = argv[++i];
4458
4474
  else flags[name] = true;
@@ -4492,8 +4508,29 @@ async function confirmRemote(config, flags) {
4492
4508
  if (typed.trim() !== host) throw new UsageError("The hostname does not match. badday did not run.");
4493
4509
  return true;
4494
4510
  }
4511
+ function compact(result, report) {
4512
+ const count = (verdict) => result.checks.filter((c) => c.verdict === verdict).length;
4513
+ return {
4514
+ report,
4515
+ tool: result.tool,
4516
+ target: result.target,
4517
+ durationMs: result.durationMs,
4518
+ records: result.records,
4519
+ counts: { fail: count("fail"), warning: count("warning"), "not-configured": count("not-configured"), pass: count("pass") },
4520
+ checks: result.checks.map((c) => ({
4521
+ id: c.id,
4522
+ pack: c.pack,
4523
+ verdict: c.verdict,
4524
+ title: c.title,
4525
+ summary: c.summary,
4526
+ facts: c.evidence?.facts.length ? c.evidence.facts : void 0,
4527
+ fixPrompt: c.fixPrompt
4528
+ }))
4529
+ };
4530
+ }
4495
4531
  async function execute(config, flags, target, allowRemote) {
4496
- const json2 = !!flags["--json"];
4532
+ const full = !!flags["--json-full"];
4533
+ const json2 = full || !!flags["--json"];
4497
4534
  const result = await run(config, {
4498
4535
  checks,
4499
4536
  allowRemote,
@@ -4504,9 +4541,9 @@ async function execute(config, flags, target, allowRemote) {
4504
4541
  `);
4505
4542
  }
4506
4543
  });
4507
- const htmlFile = flags["--no-html"] || json2 && !flags["--html"] ? null : resolve5(text(flags, "--html") ?? "badday-report.html");
4544
+ const htmlFile = flags["--no-html"] ? null : resolve5(text(flags, "--html") ?? "badday-report.html");
4508
4545
  if (htmlFile) writeFileSync4(htmlFile, renderHtml(result));
4509
- if (json2) console.log(JSON.stringify(result, null, 2));
4546
+ if (json2) console.log(JSON.stringify(full ? { report: htmlFile, ...result } : compact(result, htmlFile), null, 2));
4510
4547
  else {
4511
4548
  process.stdout.write(renderTerminal(result, { color: process.stdout.isTTY && !process.env.NO_COLOR, width: process.stdout.columns, detail: !!flags["--detail"] }));
4512
4549
  if (htmlFile) console.log(`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "badday",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Give your backend a bad day before production does.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -9,7 +9,7 @@
9
9
  },
10
10
  "scripts": {
11
11
  "status": "node scripts/status.mjs",
12
- "test": "node scripts/test-client.mjs && node scripts/test-learn.mjs && node scripts/test.mjs",
12
+ "test": "node scripts/test-client.mjs && node scripts/test-learn.mjs && node scripts/test-rate-limit.mjs && node scripts/test.mjs",
13
13
  "build": "node scripts/build.mjs",
14
14
  "typecheck": "tsc --noEmit",
15
15
  "report:sample": "node scripts/sample-report.mjs",
@@ -47,5 +47,7 @@
47
47
  "cli",
48
48
  "http",
49
49
  "backend"
50
- ]
50
+ ],
51
+ "author": "Umar Farooq",
52
+ "packageManager": "pnpm@10.33.2"
51
53
  }