@t0.labs/daxta 0.4.15 → 0.4.17

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/README.md CHANGED
@@ -181,10 +181,11 @@ Format: `{Title} {path} [{METHOD}] (integration)`
181
181
  - Skip the title and docs fall back to the path.
182
182
  - `it()` example names: `{outcome} when {condition}` — e.g. `creates mock tbs when payload is valid`. No path, no `[POST]`, no status (status comes from the recorded hit).
183
183
  - `daxta titles` lists file:line for both rules; pick a suggestion, type custom, or skip.
184
- - **Before tests:** Jest `globalSetup` always scans (plugin). `daxta test` scans too, then starts Jest. `daxta titles --check --strict` or `DAXTA_TITLE_CHECK=strict` fails CI.
184
+ - **Before tests:** `daxta install` and `daxta test` ask in the terminal (TTY). `pnpm test:integration` also asks via Jest `globalSetup` when stdin is a TTY. CI only prints. `--yes` / `CI=1` skip the questions.
185
185
 
186
186
  ```bash
187
- daxta titles # interactive
187
+ daxta titles # interactive (y = this recommended, a = all remaining)
188
+ daxta titles --yes # rewrite every hit with the recommended name
188
189
  daxta titles --check # report only
189
190
  ```
190
191
 
@@ -2511,23 +2511,24 @@
2511
2511
  };
2512
2512
 
2513
2513
  /**
2514
- * Use only headers that were on this recorded request.
2515
- * Empty headers (e.g. 401 missing-auth cases) must stay empty — never inject env auth.
2516
- * When headers exist, env can override values for the same keys (live tokens).
2514
+ * Active Try-it header group wins: switching the group at the top overwrites
2515
+ * the example request headers (Send + cURL + Headers panel).
2516
+ * If the group is empty, fall back to what was recorded.
2517
2517
  */
2518
2518
  const requestHeadersForScenario = (scenario) => {
2519
- const recorded = { ...(scenario.headers || {}) };
2520
2519
  const vars = varMap();
2521
2520
  const envHeaders = resolvedHeaders();
2522
- const envByLower = {};
2523
- for (const [name, value] of Object.entries(envHeaders)) {
2524
- envByLower[String(name).toLowerCase()] = value;
2521
+ if (Object.keys(envHeaders).length) {
2522
+ const out = {};
2523
+ for (const [name, value] of Object.entries(envHeaders)) {
2524
+ out[name] = String(interpolate(value, vars));
2525
+ }
2526
+ return out;
2525
2527
  }
2528
+ const recorded = { ...(scenario.headers || {}) };
2526
2529
  const out = {};
2527
2530
  for (const [name, value] of Object.entries(recorded)) {
2528
- const fromEnv = envByLower[String(name).toLowerCase()];
2529
- const raw = fromEnv != null && String(fromEnv).trim() !== "" ? fromEnv : value;
2530
- out[name] = String(interpolate(raw, vars));
2531
+ out[name] = String(interpolate(value, vars));
2531
2532
  }
2532
2533
  return out;
2533
2534
  };
@@ -2921,7 +2922,7 @@
2921
2922
  const scenario = item.scenarios[scenarioIndex] || { status: 0, pathParams: {}, query: {}, headers: {}, name: "" };
2922
2923
  const fields = item.docs.fields || [];
2923
2924
  ensureRequiredHeaderGroup(item.op);
2924
- const recordedHeaders = scenario.headers || {};
2925
+ const displayHeaders = requestHeadersForScenario(scenario);
2925
2926
  const recordedOk = scenario.status >= 200 && scenario.status < 300;
2926
2927
  const statusText = STATUS[scenario.status] || item.op.responses?.[String(scenario.status)]?.description || "";
2927
2928
  const emptyResponse = scenario.resBody === undefined || scenario.status === 204;
@@ -2934,9 +2935,9 @@
2934
2935
  const displayEmpty = showingLive ? displayBody === undefined || displayBody === "" : emptyResponse;
2935
2936
  const resCopyText = displayEmpty ? null : copyBodyText(displayBody);
2936
2937
  const responseTitle = showingLive ? "Live response" : "Recorded response";
2937
- const headersHtml = Object.keys(recordedHeaders).length
2938
- ? Object.entries(recordedHeaders).map(([name, value]) => kv(name, value)).join("")
2939
- : `<div class="meta-empty">No headers on this recorded request</div>`;
2938
+ const headersHtml = Object.keys(displayHeaders).length
2939
+ ? Object.entries(displayHeaders).map(([name, value]) => kv(name, value)).join("")
2940
+ : `<div class="meta-empty">No headers in this header group</div>`;
2940
2941
  const pathParamsHtml = Object.entries(scenario.pathParams || {})
2941
2942
  .map(([name, value]) => kv(name, value))
2942
2943
  .join("");
@@ -41,6 +41,7 @@ const inject_main_1 = require("./inject-main");
41
41
  const discover_test_1 = require("./discover-test");
42
42
  const jest_hooks_1 = require("./jest-hooks");
43
43
  const tree_1 = require("./tree");
44
+ const titles_1 = require("./titles");
44
45
  const ui_1 = require("./ui");
45
46
  function readJson(filePath) {
46
47
  return JSON.parse((0, fs_1.readFileSync)(filePath, 'utf8'));
@@ -331,11 +332,13 @@ async function installDaxta(options = {}) {
331
332
  }
332
333
  if (!dryRun) {
333
334
  await (0, tree_1.runTreeWizard)({ embedded: true, yes: Boolean(options.yes) });
335
+ await (0, titles_1.runTitleCheck)({ cwd, yes: Boolean(options.yes) });
334
336
  }
335
337
  (0, ui_1.box)('Done', [
336
338
  `${ui_1.c.green('✔')} DAxTA wired for ${ui_1.c.bold(project)}`,
337
339
  `${ui_1.c.dim('env')} ${ui_1.c.cyan('DAXTA_DOCS=true')} written (set ${ui_1.c.cyan('false')} to disable /docs)`,
338
- `${ui_1.c.dim('tests')} run your usual script — Docs ready prints when Jest finishes`,
340
+ `${ui_1.c.dim('tests')} run your usual script — naming prompts run first, Docs ready at the end`,
341
+ `${ui_1.c.dim('names')} ${ui_1.c.cyan('daxta titles')} to re-label TEST_TITLE / it() cases`,
339
342
  `${ui_1.c.dim('sidebar')} ${ui_1.c.cyan('daxta tree')} anytime to re-arrange folders`,
340
343
  ]);
341
344
  const wired = testScript && pkg.scripts?.[testScript] ? testScript : null;
package/dist/cli/main.js CHANGED
@@ -19,7 +19,7 @@ Usage:
19
19
  daxta init (alias of install)
20
20
  daxta uninstall [--yes] [--dry-run] [--keep-dep] [--fast]
21
21
  daxta migrate [--yes] (force upgrade + sidebar prompts)
22
- daxta titles [--check] [--strict]
22
+ daxta titles [--check] [--yes] [--strict]
23
23
  daxta test [--script <name>] [--config <jest.json>] [--serve] [--port <n>] [--yes] [--strict]
24
24
  daxta build
25
25
  daxta serve [--port <n>]
@@ -87,6 +87,7 @@ async function main() {
87
87
  (0, migrate_1.reportMigration)({ ...migration, skipped: false });
88
88
  }
89
89
  await (0, tree_1.runTreeWizard)({ embedded: true, yes: Boolean(flags.yes) });
90
+ await (0, titles_1.runTitleCheck)({ yes: Boolean(flags.yes) });
90
91
  return;
91
92
  }
92
93
  if (command === 'uninstall' || command === 'remove') {
@@ -116,6 +117,7 @@ async function main() {
116
117
  if (command === 'titles' || command === 'title') {
117
118
  const code = await (0, titles_1.runTitleCheck)({
118
119
  checkOnly: Boolean(flags.check),
120
+ apply: Boolean(flags.yes) && !flags.check,
119
121
  yes: Boolean(flags.yes),
120
122
  strict: Boolean(flags.strict),
121
123
  });
package/dist/cli/test.js CHANGED
@@ -95,7 +95,7 @@ async function runDaxtaTest(options = {}) {
95
95
  process.exitCode = 1;
96
96
  return;
97
97
  }
98
- const titleExit = await (0, titles_1.runTitleCheck)({ cwd, checkOnly: true, yes: true, strict });
98
+ const titleExit = await (0, titles_1.runTitleCheck)({ cwd, yes, strict });
99
99
  if (titleExit !== 0) {
100
100
  process.exitCode = titleExit;
101
101
  return;
@@ -2,5 +2,6 @@ export declare function runTitleCheck(options: {
2
2
  cwd?: string;
3
3
  checkOnly?: boolean;
4
4
  yes?: boolean;
5
+ apply?: boolean;
5
6
  strict?: boolean;
6
7
  }): Promise<number>;
@@ -26,12 +26,16 @@ async function pickFromSuggestions(finding, extra, validate) {
26
26
  const mark = index === 0 ? ui_1.c.dim(' (recommended)') : '';
27
27
  console.log(` ${ui_1.c.cyan(String(index + 1))} ${name}${mark}`);
28
28
  });
29
- console.log(` ${ui_1.c.cyan('s')} skip`);
30
- console.log(` ${ui_1.c.cyan('c')} custom`);
31
- const answer = await prompt(` ${ui_1.c.cyan('›')} `);
32
- if (!answer || answer.toLowerCase() === 's')
29
+ console.log(` ${ui_1.c.cyan('1–3')} pick ${ui_1.c.cyan('y')} this recommended ${ui_1.c.cyan('a')} all remaining recommended ${ui_1.c.cyan('s')} skip ${ui_1.c.cyan('c')} custom`);
30
+ const answer = (await prompt(` ${ui_1.c.cyan('›')} `)).trim();
31
+ const lower = answer.toLowerCase();
32
+ if (!answer || lower === 's')
33
33
  return 'skip';
34
- if (answer.toLowerCase() === 'c') {
34
+ if (lower === 'a' || lower === 'all')
35
+ return 'all';
36
+ if (lower === 'y' || lower === 'yes')
37
+ return suggestions[0] ?? 'skip';
38
+ if (lower === 'c') {
35
39
  const custom = await prompt(` ${ui_1.c.dim('text')} ${ui_1.c.cyan('›')} `);
36
40
  if (!validate(custom)) {
37
41
  console.log(` ${ui_1.c.yellow('!')} does not match the format — skipped`);
@@ -46,6 +50,40 @@ async function pickFromSuggestions(finding, extra, validate) {
46
50
  return answer;
47
51
  return 'skip';
48
52
  }
53
+ function writeTitle(cwd, finding) {
54
+ const name = finding.suggestions[0];
55
+ if (!name || !(0, test_title_1.isHumanOperationTitle)(name))
56
+ return false;
57
+ return (0, scan_1.applyTitle)(cwd, finding, name);
58
+ }
59
+ function writeIt(cwd, finding) {
60
+ const name = finding.suggestions[0];
61
+ if (!name || !(0, it_case_1.isValidItCase)(name))
62
+ return false;
63
+ return (0, scan_1.applyItCase)(cwd, finding, name);
64
+ }
65
+ function applyAllRecommended(cwd, titles, cases, fromTitleIndex, fromCaseIndex) {
66
+ let written = 0;
67
+ let skipped = 0;
68
+ for (let i = fromTitleIndex; i < titles.length; i += 1) {
69
+ if (writeTitle(cwd, titles[i])) {
70
+ console.log(` ${ui_1.c.green('✔')} ${titles[i].suggestions[0]} ${ui_1.c.dim(titles[i].file + ':' + titles[i].line)}`);
71
+ written += 1;
72
+ }
73
+ else
74
+ skipped += 1;
75
+ }
76
+ const caseStart = fromTitleIndex < titles.length ? 0 : fromCaseIndex;
77
+ for (let i = caseStart; i < cases.length; i += 1) {
78
+ if (writeIt(cwd, cases[i])) {
79
+ console.log(` ${ui_1.c.green('✔')} ${cases[i].suggestions[0]} ${ui_1.c.dim(cases[i].file + ':' + cases[i].line)}`);
80
+ written += 1;
81
+ }
82
+ else
83
+ skipped += 1;
84
+ }
85
+ return { written, skipped };
86
+ }
49
87
  async function runTitleCheck(options) {
50
88
  const cwd = options.cwd ?? process.cwd();
51
89
  const report = (0, scan_1.scanTestNaming)(cwd);
@@ -58,6 +96,15 @@ async function runTitleCheck(options) {
58
96
  }
59
97
  return 0;
60
98
  }
99
+ const applyAll = Boolean(options.apply);
100
+ if (applyAll) {
101
+ (0, ui_1.banner)('Test naming', 'applying recommended titles + it() names');
102
+ const result = applyAllRecommended(cwd, report.titles, report.cases, 0, 0);
103
+ console.log('');
104
+ console.log(` ${ui_1.c.green('✔')} ${result.written} updated ${ui_1.c.dim(`${result.skipped} skipped`)}`);
105
+ console.log('');
106
+ return options.strict && result.skipped > 0 ? 1 : 0;
107
+ }
61
108
  if (options.checkOnly || options.yes || !process.stdin.isTTY) {
62
109
  (0, scan_1.printNamingFindings)(report, ui_1.c);
63
110
  return options.strict ? 1 : 0;
@@ -65,11 +112,21 @@ async function runTitleCheck(options) {
65
112
  (0, ui_1.banner)('Test naming', 'runs before Jest — docs / Postman labels');
66
113
  console.log(` ${ui_1.c.dim('Title')} Create Mock Tbs /v1/admin/mock-tbs [POST] (integration)`);
67
114
  console.log(` ${ui_1.c.dim('it()')} creates mock tbs when payload is valid`);
68
- console.log(` ${ui_1.c.yellow(String(total))} to review — pick a suggestion, custom, or skip.`);
115
+ console.log(` ${ui_1.c.yellow(String(total))} to review — ${ui_1.c.cyan('y')} one recommended, ${ui_1.c.cyan('a')} all remaining, ${ui_1.c.cyan('s')} skip.`);
69
116
  let written = 0;
70
117
  let skipped = 0;
71
- for (const finding of report.titles) {
118
+ for (let i = 0; i < report.titles.length; i += 1) {
119
+ const finding = report.titles[i];
72
120
  const choice = await pickFromSuggestions(finding, `docs would show ${finding.path}`, test_title_1.isHumanOperationTitle);
121
+ if (choice === 'all') {
122
+ const rest = applyAllRecommended(cwd, report.titles, report.cases, i, 0);
123
+ written += rest.written;
124
+ skipped += rest.skipped;
125
+ console.log('');
126
+ console.log(` ${ui_1.c.green('✔')} ${written} updated ${ui_1.c.dim(`${skipped} skipped`)}`);
127
+ console.log('');
128
+ return options.strict && skipped > 0 ? 1 : 0;
129
+ }
73
130
  if (!choice || choice === 'skip') {
74
131
  skipped += 1;
75
132
  continue;
@@ -83,8 +140,15 @@ async function runTitleCheck(options) {
83
140
  skipped += 1;
84
141
  }
85
142
  }
86
- for (const finding of report.cases) {
143
+ for (let i = 0; i < report.cases.length; i += 1) {
144
+ const finding = report.cases[i];
87
145
  const choice = await pickFromSuggestions(finding, finding.section ? `section ${finding.section}` : 'it() example name', it_case_1.isValidItCase);
146
+ if (choice === 'all') {
147
+ const rest = applyAllRecommended(cwd, [], report.cases, 0, i);
148
+ written += rest.written;
149
+ skipped += rest.skipped;
150
+ break;
151
+ }
88
152
  if (!choice || choice === 'skip') {
89
153
  skipped += 1;
90
154
  continue;
@@ -2,15 +2,24 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = daxtaGlobalSetup;
4
4
  const recorder_1 = require("../recorder");
5
+ const titles_1 = require("../cli/titles");
5
6
  const scan_1 = require("../titles/scan");
6
7
  const ui_1 = require("../cli/ui");
7
8
  async function daxtaGlobalSetup() {
8
9
  (0, recorder_1.clearWorkerHits)();
9
10
  try {
11
+ if (process.env.DAXTA_TITLE_CHECK === 'off')
12
+ return;
10
13
  const strict = process.env.DAXTA_TITLE_CHECK === 'strict';
11
- const off = process.env.DAXTA_TITLE_CHECK === 'off';
12
- if (off)
14
+ const ci = Boolean(process.env.CI);
15
+ const canAsk = Boolean(process.stdin.isTTY) && !ci && process.env.DAXTA_TITLE_CHECK !== 'warn';
16
+ if (canAsk) {
17
+ const code = await (0, titles_1.runTitleCheck)({ strict });
18
+ if (strict && code) {
19
+ throw new Error('DAxTA: test naming off format. Fix with the prompts or `daxta titles`.');
20
+ }
13
21
  return;
22
+ }
14
23
  const report = (0, scan_1.scanTestNaming)(process.cwd());
15
24
  if (!report.titles.length && !report.cases.length)
16
25
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@t0.labs/daxta",
3
- "version": "0.4.15",
3
+ "version": "0.4.17",
4
4
  "description": "DAxTA \u2014 docs from Nest integration traffic + DTO field CLI / Try-it",
5
5
  "license": "MIT",
6
6
  "repository": {