@dads-framework/testing 0.0.0-stage → 0.1.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.
Files changed (125) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +215 -2
  3. package/bin/dad-test.js +3 -0
  4. package/dist/cli-arguments.d.ts +26 -0
  5. package/dist/cli-arguments.d.ts.map +1 -0
  6. package/dist/cli-arguments.js +90 -0
  7. package/dist/cli-arguments.js.map +1 -0
  8. package/dist/cli-output.d.ts +8 -0
  9. package/dist/cli-output.d.ts.map +1 -0
  10. package/dist/cli-output.js +11 -0
  11. package/dist/cli-output.js.map +1 -0
  12. package/dist/cli.d.ts +3 -0
  13. package/dist/cli.d.ts.map +1 -0
  14. package/dist/cli.js +14 -0
  15. package/dist/cli.js.map +1 -0
  16. package/dist/commands/explain.d.ts +8 -0
  17. package/dist/commands/explain.d.ts.map +1 -0
  18. package/dist/commands/explain.js +39 -0
  19. package/dist/commands/explain.js.map +1 -0
  20. package/dist/commands/init.d.ts +9 -0
  21. package/dist/commands/init.d.ts.map +1 -0
  22. package/dist/commands/init.js +57 -0
  23. package/dist/commands/init.js.map +1 -0
  24. package/dist/commands/plan-run.d.ts +8 -0
  25. package/dist/commands/plan-run.d.ts.map +1 -0
  26. package/dist/commands/plan-run.js +93 -0
  27. package/dist/commands/plan-run.js.map +1 -0
  28. package/dist/dad-test-cli.d.ts +33 -0
  29. package/dist/dad-test-cli.d.ts.map +1 -0
  30. package/dist/dad-test-cli.js +52 -0
  31. package/dist/dad-test-cli.js.map +1 -0
  32. package/dist/explain-plan.d.ts +86 -0
  33. package/dist/explain-plan.d.ts.map +1 -0
  34. package/dist/explain-plan.js +302 -0
  35. package/dist/explain-plan.js.map +1 -0
  36. package/dist/index.d.ts +13 -0
  37. package/dist/index.d.ts.map +1 -0
  38. package/dist/index.js +13 -0
  39. package/dist/index.js.map +1 -0
  40. package/dist/init/check-testing-manifest.d.ts +11 -0
  41. package/dist/init/check-testing-manifest.d.ts.map +1 -0
  42. package/dist/init/check-testing-manifest.js +166 -0
  43. package/dist/init/check-testing-manifest.js.map +1 -0
  44. package/dist/init/describe-error.d.ts +11 -0
  45. package/dist/init/describe-error.d.ts.map +1 -0
  46. package/dist/init/describe-error.js +13 -0
  47. package/dist/init/describe-error.js.map +1 -0
  48. package/dist/init/detect-workspace.d.ts +21 -0
  49. package/dist/init/detect-workspace.d.ts.map +1 -0
  50. package/dist/init/detect-workspace.js +133 -0
  51. package/dist/init/detect-workspace.js.map +1 -0
  52. package/dist/init/infer-one-package.d.ts +43 -0
  53. package/dist/init/infer-one-package.d.ts.map +1 -0
  54. package/dist/init/infer-one-package.js +173 -0
  55. package/dist/init/infer-one-package.js.map +1 -0
  56. package/dist/init/infer-testing-manifest.d.ts +60 -0
  57. package/dist/init/infer-testing-manifest.d.ts.map +1 -0
  58. package/dist/init/infer-testing-manifest.js +90 -0
  59. package/dist/init/infer-testing-manifest.js.map +1 -0
  60. package/dist/init/init-testing-manifest.d.ts +30 -0
  61. package/dist/init/init-testing-manifest.d.ts.map +1 -0
  62. package/dist/init/init-testing-manifest.js +205 -0
  63. package/dist/init/init-testing-manifest.js.map +1 -0
  64. package/dist/init/package-inventory.d.ts +21 -0
  65. package/dist/init/package-inventory.d.ts.map +1 -0
  66. package/dist/init/package-inventory.js +215 -0
  67. package/dist/init/package-inventory.js.map +1 -0
  68. package/dist/init/pnpm-workspace-yaml.d.ts +15 -0
  69. package/dist/init/pnpm-workspace-yaml.d.ts.map +1 -0
  70. package/dist/init/pnpm-workspace-yaml.js +158 -0
  71. package/dist/init/pnpm-workspace-yaml.js.map +1 -0
  72. package/dist/init/project-ids.d.ts +18 -0
  73. package/dist/init/project-ids.d.ts.map +1 -0
  74. package/dist/init/project-ids.js +54 -0
  75. package/dist/init/project-ids.js.map +1 -0
  76. package/dist/init/strip-json-comments.d.ts +9 -0
  77. package/dist/init/strip-json-comments.d.ts.map +1 -0
  78. package/dist/init/strip-json-comments.js +119 -0
  79. package/dist/init/strip-json-comments.js.map +1 -0
  80. package/dist/init/workspace-glob.d.ts +22 -0
  81. package/dist/init/workspace-glob.d.ts.map +1 -0
  82. package/dist/init/workspace-glob.js +154 -0
  83. package/dist/init/workspace-glob.js.map +1 -0
  84. package/dist/init/workspace-relative-path.d.ts +11 -0
  85. package/dist/init/workspace-relative-path.d.ts.map +1 -0
  86. package/dist/init/workspace-relative-path.js +17 -0
  87. package/dist/init/workspace-relative-path.js.map +1 -0
  88. package/dist/native-platform.d.ts +19 -0
  89. package/dist/native-platform.d.ts.map +1 -0
  90. package/dist/native-platform.js +115 -0
  91. package/dist/native-platform.js.map +1 -0
  92. package/dist/parse-guards.d.ts +13 -0
  93. package/dist/parse-guards.d.ts.map +1 -0
  94. package/dist/parse-guards.js +17 -0
  95. package/dist/parse-guards.js.map +1 -0
  96. package/dist/path-ownership.d.ts +17 -0
  97. package/dist/path-ownership.d.ts.map +1 -0
  98. package/dist/path-ownership.js +37 -0
  99. package/dist/path-ownership.js.map +1 -0
  100. package/dist/plan-issues.d.ts +17 -0
  101. package/dist/plan-issues.d.ts.map +1 -0
  102. package/dist/plan-issues.js +39 -0
  103. package/dist/plan-issues.js.map +1 -0
  104. package/dist/plan-reasons.d.ts +3 -0
  105. package/dist/plan-reasons.d.ts.map +1 -0
  106. package/dist/plan-reasons.js +14 -0
  107. package/dist/plan-reasons.js.map +1 -0
  108. package/dist/testing-api.d.ts +115 -0
  109. package/dist/testing-api.d.ts.map +1 -0
  110. package/dist/testing-api.js +96 -0
  111. package/dist/testing-api.js.map +1 -0
  112. package/dist/testing-manifest.d.ts +59 -0
  113. package/dist/testing-manifest.d.ts.map +1 -0
  114. package/dist/testing-manifest.js +196 -0
  115. package/dist/testing-manifest.js.map +1 -0
  116. package/dist/testing-report.d.ts +77 -0
  117. package/dist/testing-report.d.ts.map +1 -0
  118. package/dist/testing-report.js +184 -0
  119. package/dist/testing-report.js.map +1 -0
  120. package/dist/testing.tsbuildinfo +1 -0
  121. package/dist/write-files-atomically.d.ts +11 -0
  122. package/dist/write-files-atomically.d.ts.map +1 -0
  123. package/dist/write-files-atomically.js +30 -0
  124. package/dist/write-files-atomically.js.map +1 -0
  125. package/package.json +43 -4
@@ -0,0 +1,60 @@
1
+ import type { TestingManifest, TestingManifestImpactMode, TestingManifestTaskKind } from "../testing-manifest.js";
2
+ import type { DetectedWorkspace } from "./detect-workspace.js";
3
+ import type { WorkspacePackage } from "./package-inventory.js";
4
+ import type { ProjectIdSource } from "./project-ids.js";
5
+ /**
6
+ * Turns what was detected into the manifest and the report, without touching
7
+ * the file system. Everything the generator concluded is recorded as an
8
+ * inference, and everything it could not read is recorded as unsupported, so
9
+ * the report answers "why does my manifest look like this?" on its own.
10
+ */
11
+ export type InitInferenceKind = "package-manager" | "workspace-pattern" | "root-package" | "project-id" | "task" | "depends-on" | "fallback-dependency";
12
+ export type InitInference = {
13
+ readonly kind: InitInferenceKind;
14
+ readonly subject: string;
15
+ readonly detail: string;
16
+ };
17
+ export type InitUnsupported = {
18
+ readonly subject: string;
19
+ readonly message: string;
20
+ };
21
+ export type InitSkipReason = "no-recognized-scripts" | "invalid-package-json";
22
+ export type InitReportTask = {
23
+ readonly id: string;
24
+ readonly script: string;
25
+ readonly kind: TestingManifestTaskKind;
26
+ readonly impactMode: TestingManifestImpactMode;
27
+ };
28
+ export type InitReportPackage = {
29
+ readonly directory: string;
30
+ readonly name?: string;
31
+ readonly projectId?: string;
32
+ readonly projectIdSource?: ProjectIdSource;
33
+ readonly tasks: readonly InitReportTask[];
34
+ readonly skipped?: InitSkipReason;
35
+ };
36
+ export type InitValidation = {
37
+ readonly method: "native" | "structural" | "none";
38
+ readonly ok: boolean;
39
+ readonly messages: readonly string[];
40
+ readonly selectedTaskCount?: number;
41
+ };
42
+ export type InitReport = {
43
+ readonly schemaVersion: 1;
44
+ readonly generator: {
45
+ readonly name: "@dads-framework/testing";
46
+ readonly command: "dad-test init";
47
+ };
48
+ readonly workspace: Pick<DetectedWorkspace, "packageManager" | "packageManagerSource" | "patternSource" | "patterns" | "ignoredWorkspaceKeys">;
49
+ readonly packages: readonly InitReportPackage[];
50
+ readonly inferences: readonly InitInference[];
51
+ readonly unsupported: readonly InitUnsupported[];
52
+ readonly validation: InitValidation;
53
+ readonly manifestChecksum: string | null;
54
+ };
55
+ export type InferredTesting = {
56
+ readonly manifest: TestingManifest | undefined;
57
+ readonly report: Omit<InitReport, "validation" | "manifestChecksum">;
58
+ };
59
+ export declare function inferTestingManifest(workspace: DetectedWorkspace, packages: readonly WorkspacePackage[]): InferredTesting;
60
+ //# sourceMappingURL=infer-testing-manifest.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"infer-testing-manifest.d.ts","sourceRoot":"","sources":["../../src/init/infer-testing-manifest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,yBAAyB,EAGzB,uBAAuB,EACxB,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAQ/D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAExD;;;;;GAKG;AAEH,MAAM,MAAM,iBAAiB,GACzB,iBAAiB,GACjB,mBAAmB,GACnB,cAAc,GACd,YAAY,GACZ,MAAM,GACN,YAAY,GACZ,qBAAqB,CAAC;AAE1B,MAAM,MAAM,aAAa,GAAG;IAC1B,QAAQ,CAAC,IAAI,EAAE,iBAAiB,CAAC;IACjC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM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,EAAE,SAAS,iBAAiB,EAAE,CAAC;IAChD,QAAQ,CAAC,UAAU,EAAE,SAAS,aAAa,EAAE,CAAC;IAC9C,QAAQ,CAAC,WAAW,EAAE,SAAS,eAAe,EAAE,CAAC;IACjD,QAAQ,CAAC,UAAU,EAAE,cAAc,CAAC;IACpC,QAAQ,CAAC,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1C,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,QAAQ,CAAC,QAAQ,EAAE,eAAe,GAAG,SAAS,CAAC;IAC/C,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,UAAU,EAAE,YAAY,GAAG,kBAAkB,CAAC,CAAC;CACtE,CAAC;AASF,wBAAgB,oBAAoB,CAClC,SAAS,EAAE,iBAAiB,EAC5B,QAAQ,EAAE,SAAS,gBAAgB,EAAE,GACpC,eAAe,CAyCjB"}
@@ -0,0 +1,90 @@
1
+ import { compareText, identifyProjects, inferOnePackage, skippedReportPackage, } from "./infer-one-package.js";
2
+ export function inferTestingManifest(workspace, packages) {
3
+ const inferences = workspaceInferences(workspace);
4
+ const identified = identifyProjects(packages);
5
+ const inferred = inferPackages(workspace, packages, identified, inferences);
6
+ const sortedTasks = [...inferred.tasks].sort((left, right) => compareText(left.id, right.id));
7
+ const report = {
8
+ schemaVersion: 1,
9
+ generator: { name: "@dads-framework/testing", command: "dad-test init" },
10
+ workspace: {
11
+ packageManager: workspace.packageManager,
12
+ packageManagerSource: workspace.packageManagerSource,
13
+ patternSource: workspace.patternSource,
14
+ patterns: workspace.patterns,
15
+ ignoredWorkspaceKeys: workspace.ignoredWorkspaceKeys,
16
+ },
17
+ packages: inferred.reportPackages,
18
+ inferences,
19
+ unsupported: [
20
+ ...workspace.unsupported,
21
+ ...packages.flatMap((workspacePackage) => workspacePackage.unsupported),
22
+ ],
23
+ };
24
+ if (sortedTasks.length === 0)
25
+ return { manifest: undefined, report };
26
+ return {
27
+ manifest: {
28
+ schemaVersion: 1,
29
+ workspace: {
30
+ root: ".",
31
+ fullFallback: { taskIds: sortedTasks.map((task) => task.id) },
32
+ },
33
+ projects: [...inferred.projects].sort((left, right) => compareText(left.id, right.id)),
34
+ tasks: sortedTasks,
35
+ },
36
+ report,
37
+ };
38
+ }
39
+ /** What the workspace itself explains: how scripts run, and where packages were sought. */
40
+ function workspaceInferences(workspace) {
41
+ const inferences = [
42
+ {
43
+ kind: "package-manager",
44
+ subject: workspace.packageManager,
45
+ detail: workspace.packageManagerSource === "default"
46
+ ? "no lockfile was found; scripts run with npm"
47
+ : `from ${workspace.packageManagerSource}`,
48
+ },
49
+ ];
50
+ for (const pattern of workspace.patterns) {
51
+ inferences.push({
52
+ kind: "workspace-pattern",
53
+ subject: pattern,
54
+ detail: `from ${workspace.patternSource}`,
55
+ });
56
+ }
57
+ if (workspace.patternSource === "single-package") {
58
+ inferences.push({
59
+ kind: "root-package",
60
+ subject: ".",
61
+ detail: "no workspace patterns were declared; the root is the package",
62
+ });
63
+ }
64
+ return inferences;
65
+ }
66
+ /** Every package reaches the report, whether or not it became a project. */
67
+ function inferPackages(workspace, packages, identified, inferences) {
68
+ const projects = [];
69
+ const tasks = [];
70
+ const reportPackages = [];
71
+ for (const workspacePackage of packages) {
72
+ const assignment = identified.idByDirectory.get(workspacePackage.directory);
73
+ if (assignment === undefined) {
74
+ reportPackages.push(skippedReportPackage(workspacePackage));
75
+ continue;
76
+ }
77
+ const inferred = inferOnePackage({
78
+ packageManager: workspace.packageManager,
79
+ workspacePackage,
80
+ assignment,
81
+ identified,
82
+ inferences,
83
+ });
84
+ projects.push(inferred.project);
85
+ tasks.push(...inferred.tasks);
86
+ reportPackages.push(inferred.reportPackage);
87
+ }
88
+ return { projects, tasks, reportPackages };
89
+ }
90
+ //# sourceMappingURL=infer-testing-manifest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"infer-testing-manifest.js","sourceRoot":"","sources":["../../src/init/infer-testing-manifest.ts"],"names":[],"mappings":"AAQA,OA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A8B,EAC9B,UAA2B;IAE3B,MAAM,QAAQ,GAA6B,EAAE,CAAC;IAC9C,MAAM,KAAK,GAA0B,EAAE,CAAC;IACxC,MAAM,cAAc,GAAwB,EAAE,CAAC;IAE/C,KAAK,MAAM,gBAAgB,IAAI,QAAQ,EAAE,CAAC;QACxC,MAAM,UAAU,GAAG,UAAU,CAAC,aAAa,CAAC,GAAG,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC;QAC5E,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;YAC7B,cAAc,CAAC,IAAI,CAAC,oBAAoB,CAAC,gBAAgB,CAAC,CAAC,CAAC;YAC5D,SAAS;QACX,CAAC;QACD,MAAM,QAAQ,GAAG,eAAe,CAAC;YAC/B,cAAc,EAAE,SAAS,CAAC,cAAc;YACxC,gBAAgB;YAChB,UAAU;YACV,UAAU;YACV,UAAU;SACX,CAAC,CAAC;QACH,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QAChC,KAAK,CAAC,IAAI,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;QAC9B,cAAc,CAAC,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;IAC9C,CAAC;IACD,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,cAAc,EAAE,CAAC;AAC7C,CAAC"}
@@ -0,0 +1,30 @@
1
+ import { type TestingManifest } from "../testing-manifest.js";
2
+ import { type InitReport } from "./infer-testing-manifest.js";
3
+ /**
4
+ * Generates `dads.testing.json` for a workspace that does not have one, and the
5
+ * report that explains it. A manifest only reaches its final path once it has
6
+ * been checked: structurally always, and by the native engine itself where one
7
+ * is installed. Nothing partly-valid is left behind for the next command to
8
+ * trip over, and an existing manifest is never replaced without `--force`.
9
+ */
10
+ export type InitTestingManifestOptions = {
11
+ readonly workspaceRoot: string;
12
+ readonly manifestPath?: string;
13
+ readonly force?: boolean;
14
+ /** An explicit native binary is intended for local development and test harnesses. */
15
+ readonly nativeBinary?: string;
16
+ readonly environment?: NodeJS.ProcessEnv;
17
+ /** Overrides how the native engine is found; undefined means "not installed". */
18
+ readonly resolveNativeBinary?: () => string | undefined;
19
+ };
20
+ export type InitTestingManifestResult = {
21
+ /** Workspace-relative path of the manifest that was written. */
22
+ readonly manifestPath: string;
23
+ /** Workspace-relative path of the report that explains it. */
24
+ readonly reportPath: string;
25
+ readonly manifest: TestingManifest;
26
+ readonly report: InitReport;
27
+ };
28
+ export declare const initReportFileName = "dads.testing.init-report.json";
29
+ export declare function initTestingManifest(options: InitTestingManifestOptions): Promise<InitTestingManifestResult>;
30
+ //# sourceMappingURL=init-testing-manifest.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"init-testing-manifest.d.ts","sourceRoot":"","sources":["../../src/init/init-testing-manifest.ts"],"names":[],"mappings":"AAKA,OAAO,EAGL,KAAK,eAAe,EACrB,MAAM,wBAAwB,CAAC;AAQhC,OAAO,EAEL,KAAK,UAAU,EAEhB,MAAM,6BAA6B,CAAC;AAIrC;;;;;;GAMG;AAEH,MAAM,MAAM,0BAA0B,GAAG;IACvC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;IACzB,sFAAsF;IACtF,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;IACzC,iFAAiF;IACjF,QAAQ,CAAC,mBAAmB,CAAC,EAAE,MAAM,MAAM,GAAG,SAAS,CAAC;CACzD,CAAC;AAEF,MAAM,MAAM,yBAAyB,GAAG;IACtC,gEAAgE;IAChE,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,8DAA8D;IAC9D,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,QAAQ,EAAE,eAAe,CAAC;IACnC,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;CAC7B,CAAC;AAEF,eAAO,MAAM,kBAAkB,kCAAkC,CAAC;AAoBlE,wBAAsB,mBAAmB,CACvC,OAAO,EAAE,0BAA0B,GAClC,OAAO,CAAC,yBAAyB,CAAC,CA8CpC"}
@@ -0,0 +1,205 @@
1
+ import { createHash, randomUUID } from "node:crypto";
2
+ import { existsSync, renameSync, rmSync, writeFileSync } from "node:fs";
3
+ import { dirname, join, resolve, sep } from "node:path";
4
+ import { resolveNativeTestingBinary } from "../native-platform.js";
5
+ import { planTesting } from "../testing-api.js";
6
+ import { defaultTestingManifestFileName, serializeTestingManifest, } from "../testing-manifest.js";
7
+ import { writeFilesAtomically, } from "../write-files-atomically.js";
8
+ import { checkTestingManifest } from "./check-testing-manifest.js";
9
+ import { describeError } from "./describe-error.js";
10
+ import { detectWorkspace } from "./detect-workspace.js";
11
+ import { inferTestingManifest, } from "./infer-testing-manifest.js";
12
+ import { readWorkspacePackages } from "./package-inventory.js";
13
+ import { workspaceRelative } from "./workspace-relative-path.js";
14
+ export const initReportFileName = "dads.testing.init-report.json";
15
+ const noRecognizedScripts = "No recognized test, typecheck, lint, or build scripts were found";
16
+ export async function initTestingManifest(options) {
17
+ const paths = resolveInitPaths(options);
18
+ // Checked before anything is generated: a refusal must not touch the report.
19
+ if (existsSync(paths.manifestFile) && options.force !== true) {
20
+ throw new Error(`Refusing to overwrite existing ${paths.manifestPath}; pass --force to replace it.`);
21
+ }
22
+ const workspace = detectWorkspace(paths.workspaceRoot);
23
+ const packages = readWorkspacePackages(paths.workspaceRoot, workspace.packageDirectories);
24
+ const inferred = inferTestingManifest(workspace, packages);
25
+ const buildReport = reportBuilder(inferred.report, paths.reportFile);
26
+ requireStandaloneWorkspace(paths.workspaceRoot, paths.reportFile, inferred.report);
27
+ const manifest = requireInferredManifest(inferred.manifest, buildReport);
28
+ const manifestText = requireStructurallyValid(manifest, buildReport);
29
+ const checksum = createHash("sha256").update(manifestText).digest("hex");
30
+ const nativeBinary = (options.resolveNativeBinary ?? installedNativeBinary(options))();
31
+ const report = nativeBinary === undefined
32
+ ? writeStructurallyChecked(paths, manifestText, checksum, buildReport)
33
+ : await writeEngineChecked({
34
+ paths,
35
+ manifestText,
36
+ nativeBinary,
37
+ checksum,
38
+ buildReport,
39
+ });
40
+ return {
41
+ manifestPath: paths.manifestPath,
42
+ reportPath: paths.reportPath,
43
+ manifest,
44
+ report,
45
+ };
46
+ }
47
+ /** The report is written beside the manifest, and neither may leave the workspace. */
48
+ function resolveInitPaths(options) {
49
+ const workspaceRoot = resolve(options.workspaceRoot);
50
+ const requestedPath = options.manifestPath ?? defaultTestingManifestFileName;
51
+ const manifestFile = resolve(workspaceRoot, requestedPath);
52
+ if (manifestFile !== workspaceRoot &&
53
+ !manifestFile.startsWith(`${workspaceRoot}${sep}`)) {
54
+ throw new Error(`The manifest path must stay inside the workspace: ${requestedPath}`);
55
+ }
56
+ const reportFile = join(dirname(manifestFile), initReportFileName);
57
+ return {
58
+ workspaceRoot,
59
+ manifestFile,
60
+ reportFile,
61
+ manifestPath: workspaceRelative(workspaceRoot, manifestFile),
62
+ reportPath: workspaceRelative(workspaceRoot, reportFile),
63
+ };
64
+ }
65
+ function reportBuilder(inferredReport, reportFile) {
66
+ return (validation, manifestChecksum) => {
67
+ const report = {
68
+ ...inferredReport,
69
+ validation,
70
+ manifestChecksum,
71
+ };
72
+ return {
73
+ report,
74
+ output: {
75
+ path: reportFile,
76
+ contents: `${JSON.stringify(report, null, 2)}\n`,
77
+ },
78
+ };
79
+ };
80
+ }
81
+ /** A workspace with nothing to run still gets the report that says so. */
82
+ function requireInferredManifest(manifest, buildReport) {
83
+ if (manifest !== undefined)
84
+ return manifest;
85
+ writeFilesAtomically([
86
+ buildReport({ method: "none", ok: false, messages: [`${noRecognizedScripts}.`] }, null).output,
87
+ ]);
88
+ throw new Error(`${noRecognizedScripts}; wrote ${initReportFileName} and no manifest.`);
89
+ }
90
+ /** Serialized only once it has passed, so the text that reaches disk is the text checked. */
91
+ function requireStructurallyValid(manifest, buildReport) {
92
+ const structuralMessages = checkTestingManifest(manifest);
93
+ if (structuralMessages.length === 0) {
94
+ return serializeTestingManifest(manifest);
95
+ }
96
+ writeFilesAtomically([
97
+ buildReport({ method: "structural", ok: false, messages: structuralMessages }, null).output,
98
+ ]);
99
+ throw new Error(`Generated manifest failed validation: ${structuralMessages.join(" ")}`);
100
+ }
101
+ /** Without an engine to ask, the structural check is the whole check. */
102
+ function writeStructurallyChecked(paths, manifestText, checksum, buildReport) {
103
+ const written = buildReport({ method: "structural", ok: true, messages: [] }, checksum);
104
+ writeFilesAtomically([
105
+ { path: paths.manifestFile, contents: manifestText },
106
+ written.output,
107
+ ]);
108
+ return written.report;
109
+ }
110
+ /** The engine's acceptance is what moves the manifest into place, so only the report is left. */
111
+ async function writeEngineChecked(request) {
112
+ const buildReport = request.buildReport;
113
+ const selectedTaskCount = await validateWithNativeEngine({
114
+ workspaceRoot: request.paths.workspaceRoot,
115
+ manifestFile: request.paths.manifestFile,
116
+ manifestText: request.manifestText,
117
+ nativeBinary: request.nativeBinary,
118
+ onRejected: (message, error) => {
119
+ writeFilesAtomically([
120
+ buildReport({ method: "native", ok: false, messages: [message] }, null)
121
+ .output,
122
+ ]);
123
+ return new Error(`Generated manifest was rejected by dad-test: ${message}`, {
124
+ cause: error,
125
+ });
126
+ },
127
+ });
128
+ const written = buildReport({ method: "native", ok: true, messages: [], selectedTaskCount }, request.checksum);
129
+ writeFilesAtomically([written.output]);
130
+ return written.report;
131
+ }
132
+ function requireStandaloneWorkspace(workspaceRoot, reportFile, inferredReport) {
133
+ if (!existsSync(join(workspaceRoot, "nx.json")))
134
+ return;
135
+ const message = "Nx workspace detected. Generic script discovery cannot establish Nx target coverage; use @dads-framework/testing-import-nx and review its coverage report.";
136
+ const report = {
137
+ ...inferredReport,
138
+ validation: { method: "none", ok: false, messages: [message] },
139
+ manifestChecksum: null,
140
+ unsupported: [
141
+ ...inferredReport.unsupported,
142
+ { subject: "nx.json", message },
143
+ ],
144
+ };
145
+ writeFilesAtomically([
146
+ { path: reportFile, contents: `${JSON.stringify(report, null, 2)}\n` },
147
+ ]);
148
+ throw new Error(`${message} No manifest was written.`);
149
+ }
150
+ /**
151
+ * Asks the engine that will run this manifest whether it accepts it, by
152
+ * planning a full run against a temporary copy inside the workspace. The copy
153
+ * becomes the manifest only once the engine has read it, so a rejected manifest
154
+ * is never a file anyone can run.
155
+ */
156
+ async function validateWithNativeEngine(request) {
157
+ const temporaryFile = `${request.manifestFile}.${randomUUID()}.tmp`;
158
+ writeFileSync(temporaryFile, request.manifestText, "utf8");
159
+ let selectedTaskCount;
160
+ try {
161
+ const plan = await planTesting({
162
+ workspaceRoot: request.workspaceRoot,
163
+ manifestPath: workspaceRelative(request.workspaceRoot, temporaryFile),
164
+ all: true,
165
+ taskIds: [],
166
+ nativeBinary: request.nativeBinary,
167
+ });
168
+ selectedTaskCount = plan.counts.run;
169
+ }
170
+ catch (error) {
171
+ rmSync(temporaryFile, { force: true });
172
+ throw request.onRejected(describeError(error), error);
173
+ }
174
+ try {
175
+ renameSync(temporaryFile, request.manifestFile);
176
+ }
177
+ catch (error) {
178
+ rmSync(temporaryFile, { force: true });
179
+ throw error;
180
+ }
181
+ return selectedTaskCount;
182
+ }
183
+ /**
184
+ * A workspace without the native package still generates a manifest: the
185
+ * structural check is the same set of rules. Any resolution failure means "not
186
+ * installed here", which is a supported state rather than an error.
187
+ */
188
+ function installedNativeBinary(options) {
189
+ return () => {
190
+ try {
191
+ return resolveNativeTestingBinary({
192
+ ...(options.nativeBinary === undefined
193
+ ? {}
194
+ : { explicitBinary: options.nativeBinary }),
195
+ ...(options.environment === undefined
196
+ ? {}
197
+ : { environment: options.environment }),
198
+ }).binary;
199
+ }
200
+ catch {
201
+ return undefined;
202
+ }
203
+ };
204
+ }
205
+ //# sourceMappingURL=init-testing-manifest.js.map
@@ -0,0 +1 @@
1
+ {"version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K,EAAE,IAAI,EAAE,CAAC,CAAC;QACvC,MAAM,KAAK,CAAC;IACd,CAAC;IACD,OAAO,iBAAiB,CAAC;AAC3B,CAAC;AAED;;;;GAIG;AACH,SAAS,qBAAqB,CAC5B,OAAmC;IAEnC,OAAO,GAAG,EAAE;QACV,IAAI,CAAC;YACH,OAAO,0BAA0B,CAAC;gBAChC,GAAG,CAAC,OAAO,CAAC,YAAY,KAAK,SAAS;oBACpC,CAAC,CAAC,EAAE;oBACJ,CAAC,CAAC,EAAE,cAAc,EAAE,OAAO,CAAC,YAAY,EAAE,CAAC;gBAC7C,GAAG,CAAC,OAAO,CAAC,WAAW,KAAK,SAAS;oBACnC,CAAC,CAAC,EAAE;oBACJ,CAAC,CAAC,EAAE,WAAW,EAAE,OAAO,CAAC,WAAW,EAAE,CAAC;aAC1C,CAAC,CAAC,MAAM,CAAC;QACZ,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,SAAS,CAAC;QACnB,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,21 @@
1
+ import type { InitUnsupported } from "./infer-testing-manifest.js";
2
+ /**
3
+ * What each candidate directory declares about itself: the scripts a task could
4
+ * run, and the two edges that make one package depend on another — a workspace
5
+ * dependency in `package.json`, and a project reference in `tsconfig.json`.
6
+ * Both edges are read only to widen the fallback, never to prove impact.
7
+ */
8
+ export type WorkspacePackage = {
9
+ readonly directory: string;
10
+ readonly name?: string;
11
+ readonly scripts: Readonly<Record<string, string>>;
12
+ /** Names of other inventoried packages this package declares a dependency on. */
13
+ readonly workspaceDependencies: readonly string[];
14
+ /** Directories of other inventoried packages this package's tsconfig references. */
15
+ readonly tsconfigReferences: readonly string[];
16
+ /** False when `package.json` could not be read; the package declares no tasks. */
17
+ readonly packageJsonReadable: boolean;
18
+ readonly unsupported: readonly InitUnsupported[];
19
+ };
20
+ export declare function readWorkspacePackages(workspaceRoot: string, directories: readonly string[]): readonly WorkspacePackage[];
21
+ //# sourceMappingURL=package-inventory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"package-inventory.d.ts","sourceRoot":"","sources":["../../src/init/package-inventory.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAInE;;;;;GAKG;AAEH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACnD,iFAAiF;IACjF,QAAQ,CAAC,qBAAqB,EAAE,SAAS,MAAM,EAAE,CAAC;IAClD,oFAAoF;IACpF,QAAQ,CAAC,kBAAkB,EAAE,SAAS,MAAM,EAAE,CAAC;IAC/C,kFAAkF;IAClF,QAAQ,CAAC,mBAAmB,EAAE,OAAO,CAAC;IACtC,QAAQ,CAAC,WAAW,EAAE,SAAS,eAAe,EAAE,CAAC;CAClD,CAAC;AAcF,wBAAgB,qBAAqB,CACnC,aAAa,EAAE,MAAM,EACrB,WAAW,EAAE,SAAS,MAAM,EAAE,GAC7B,SAAS,gBAAgB,EAAE,CAiC7B"}
@@ -0,0 +1,215 @@
1
+ import { existsSync, readFileSync, statSync } from "node:fs";
2
+ import { dirname, join, resolve } from "node:path";
3
+ import { isRecord, isUnknownArray } from "../parse-guards.js";
4
+ import { describeError } from "./describe-error.js";
5
+ import { stripJsonComments } from "./strip-json-comments.js";
6
+ import { workspaceRelative } from "./workspace-relative-path.js";
7
+ const dependencyFields = [
8
+ "dependencies",
9
+ "devDependencies",
10
+ "peerDependencies",
11
+ ];
12
+ export function readWorkspacePackages(workspaceRoot, directories) {
13
+ const read = directories.map((directory) => readOnePackage(workspaceRoot, directory));
14
+ const knownNames = new Set(read
15
+ .map((entry) => entry.declared?.name)
16
+ .filter((name) => name !== undefined));
17
+ const knownDirectories = new Set(read.map((entry) => entry.directory));
18
+ return read.map((entry) => {
19
+ const unsupported = [...entry.unsupported];
20
+ const declared = entry.declared;
21
+ const references = resolveTsconfigReferences(workspaceRoot, entry.directory, knownDirectories, unsupported);
22
+ const name = declared?.name;
23
+ return {
24
+ directory: entry.directory,
25
+ ...(name === undefined ? {} : { name }),
26
+ scripts: declared?.scripts ?? {},
27
+ workspaceDependencies: (declared?.dependencyNames ?? []).filter((dependency) => dependency !== name && knownNames.has(dependency)),
28
+ tsconfigReferences: references,
29
+ packageJsonReadable: declared !== undefined,
30
+ unsupported,
31
+ };
32
+ });
33
+ }
34
+ function readOnePackage(workspaceRoot, directory) {
35
+ const packageJsonPath = join(absoluteDirectory(workspaceRoot, directory), "package.json");
36
+ let text;
37
+ try {
38
+ text = readFileSync(packageJsonPath, "utf8");
39
+ }
40
+ catch (error) {
41
+ return {
42
+ directory,
43
+ declared: undefined,
44
+ unsupported: [
45
+ {
46
+ subject: joinRelative(directory, "package.json"),
47
+ message: `unreadable package.json (${describeError(error)}).`,
48
+ },
49
+ ],
50
+ };
51
+ }
52
+ try {
53
+ return { directory, declared: readPackageJson(text), unsupported: [] };
54
+ }
55
+ catch (error) {
56
+ return {
57
+ directory,
58
+ declared: undefined,
59
+ unsupported: [
60
+ {
61
+ subject: joinRelative(directory, "package.json"),
62
+ message: `${describeError(error)}.`,
63
+ },
64
+ ],
65
+ };
66
+ }
67
+ }
68
+ /**
69
+ * Reads only the fields an inferred manifest depends on, and refuses a wrong
70
+ * type rather than coercing it: a `scripts` value that is not a string would
71
+ * otherwise become a task that cannot run.
72
+ */
73
+ function readPackageJson(text) {
74
+ const parsed = JSON.parse(text);
75
+ if (!isRecord(parsed))
76
+ throw new Error("package.json must be an object");
77
+ const declaredName = readDeclaredName(parsed);
78
+ return {
79
+ ...(declaredName === undefined ? {} : { name: declaredName }),
80
+ scripts: readDeclaredScripts(parsed),
81
+ dependencyNames: readDeclaredDependencyNames(parsed),
82
+ };
83
+ }
84
+ function readDeclaredName(parsed) {
85
+ const declaredName = parsed["name"];
86
+ if (declaredName === undefined)
87
+ return undefined;
88
+ if (typeof declaredName !== "string") {
89
+ throw new Error("package.json name must be a string");
90
+ }
91
+ return declaredName;
92
+ }
93
+ /** A command that is not a string would become a task that cannot run. */
94
+ function readDeclaredScripts(parsed) {
95
+ const declaredScripts = parsed["scripts"];
96
+ if (declaredScripts === undefined)
97
+ return {};
98
+ if (!isRecord(declaredScripts)) {
99
+ throw new Error("package.json scripts must be an object");
100
+ }
101
+ const scripts = {};
102
+ for (const [scriptName, command] of Object.entries(declaredScripts)) {
103
+ if (typeof command !== "string") {
104
+ throw new Error(`package.json scripts.${scriptName} must be a string`);
105
+ }
106
+ scripts[scriptName] = command;
107
+ }
108
+ return scripts;
109
+ }
110
+ /** Every dependency field contributes names; which field it came from does not matter. */
111
+ function readDeclaredDependencyNames(parsed) {
112
+ const dependencyNames = [];
113
+ for (const field of dependencyFields) {
114
+ const declared = parsed[field];
115
+ if (declared === undefined)
116
+ continue;
117
+ if (!isRecord(declared)) {
118
+ throw new Error(`package.json ${field} must be an object`);
119
+ }
120
+ dependencyNames.push(...Object.keys(declared));
121
+ }
122
+ return dependencyNames;
123
+ }
124
+ /**
125
+ * TypeScript project references name a tsconfig, not a package, so a reference
126
+ * only becomes a dependency edge when it resolves to a directory this inventory
127
+ * already knows. Anything else is named in the report rather than dropped.
128
+ */
129
+ function resolveTsconfigReferences(workspaceRoot, directory, knownDirectories, unsupported) {
130
+ const tsconfigPath = join(absoluteDirectory(workspaceRoot, directory), "tsconfig.json");
131
+ if (!existsSync(tsconfigPath))
132
+ return [];
133
+ const declared = readDeclaredReferences(tsconfigPath, directory, unsupported);
134
+ const references = [];
135
+ for (const entry of declared) {
136
+ const referenced = referencedPackageDirectory({
137
+ workspaceRoot,
138
+ tsconfigPath,
139
+ directory,
140
+ entry,
141
+ knownDirectories,
142
+ unsupported,
143
+ });
144
+ if (referenced === undefined)
145
+ continue;
146
+ if (!references.includes(referenced))
147
+ references.push(referenced);
148
+ }
149
+ return references;
150
+ }
151
+ /**
152
+ * A tsconfig this reader cannot understand contributes no edges: the reason is
153
+ * named in the report rather than raised, because a workspace may hold a
154
+ * tsconfig no one asked `dad-test` to read.
155
+ */
156
+ function readDeclaredReferences(tsconfigPath, directory, unsupported) {
157
+ const subject = joinRelative(directory, "tsconfig.json");
158
+ let parsed;
159
+ try {
160
+ parsed = JSON.parse(stripJsonComments(readFileSync(tsconfigPath, "utf8")));
161
+ }
162
+ catch (error) {
163
+ unsupported.push({
164
+ subject,
165
+ message: `unreadable tsconfig.json (${describeError(error)}).`,
166
+ });
167
+ return [];
168
+ }
169
+ if (!isRecord(parsed)) {
170
+ unsupported.push({ subject, message: "tsconfig.json must be an object." });
171
+ return [];
172
+ }
173
+ const declared = parsed["references"];
174
+ if (declared === undefined)
175
+ return [];
176
+ if (isUnknownArray(declared))
177
+ return declared;
178
+ unsupported.push({ subject, message: "references must be an array." });
179
+ return [];
180
+ }
181
+ /** One reference becomes an edge only when it names a directory this inventory knows. */
182
+ function referencedPackageDirectory(request) {
183
+ const subject = joinRelative(request.directory, "tsconfig.json");
184
+ const path = isRecord(request.entry) ? request.entry["path"] : undefined;
185
+ if (typeof path !== "string") {
186
+ request.unsupported.push({
187
+ subject,
188
+ message: "every reference must declare a string path.",
189
+ });
190
+ return undefined;
191
+ }
192
+ const referenced = referencedDirectory(request.workspaceRoot, dirname(request.tsconfigPath), path);
193
+ if (request.knownDirectories.has(referenced))
194
+ return referenced;
195
+ request.unsupported.push({
196
+ subject,
197
+ message: `reference ${path} does not name a workspace package.`,
198
+ });
199
+ return undefined;
200
+ }
201
+ /** A reference may name a tsconfig file or the directory that holds one. */
202
+ function referencedDirectory(workspaceRoot, fromDirectory, referencePath) {
203
+ const resolved = resolve(fromDirectory, referencePath);
204
+ const namesFile = existsSync(resolved)
205
+ ? statSync(resolved).isFile()
206
+ : resolved.endsWith(".json");
207
+ return workspaceRelative(workspaceRoot, namesFile ? dirname(resolved) : resolved);
208
+ }
209
+ function absoluteDirectory(workspaceRoot, directory) {
210
+ return directory === "." ? workspaceRoot : join(workspaceRoot, directory);
211
+ }
212
+ function joinRelative(directory, file) {
213
+ return directory === "." ? file : `${directory}/${file}`;
214
+ }
215
+ //# sourceMappingURL=package-inventory.js.map