@leitwerk-dev/test-support 0.1.9 → 0.2.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 (104) hide show
  1. package/dist/{chunk-QFCJV2VA.js → chunk-2IICIB6D.js} +187 -14
  2. package/dist/chunk-2IICIB6D.js.map +1 -0
  3. package/dist/{chunk-KIDBCGNW.js → chunk-7I4OCTF3.js} +21 -26
  4. package/dist/chunk-7I4OCTF3.js.map +1 -0
  5. package/dist/{chunk-ST2C4VKX.js → chunk-KPSK7EMY.js} +39 -9
  6. package/dist/chunk-KPSK7EMY.js.map +1 -0
  7. package/dist/{chunk-R4KVUGWR.js → chunk-MV4W6NOO.js} +25 -3
  8. package/dist/chunk-MV4W6NOO.js.map +1 -0
  9. package/dist/compact-process-detail-fixture.d.ts.map +1 -1
  10. package/dist/fakes/index.js +10 -2
  11. package/dist/fakes/index.js.map +1 -1
  12. package/dist/fixtures.js +35 -2
  13. package/dist/fixtures.js.map +1 -1
  14. package/dist/http-launch.d.ts +8 -0
  15. package/dist/http-launch.d.ts.map +1 -0
  16. package/dist/index.d.ts +4 -2
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js +156 -12
  19. package/dist/index.js.map +1 -1
  20. package/dist/integration.d.ts +1 -0
  21. package/dist/integration.d.ts.map +1 -1
  22. package/dist/integration.js +66 -4
  23. package/dist/integration.js.map +1 -1
  24. package/dist/local-git.d.ts +134 -0
  25. package/dist/local-git.d.ts.map +1 -0
  26. package/dist/local-git.js +297 -0
  27. package/dist/local-git.js.map +1 -0
  28. package/dist/model-provider-fixtures.d.ts +7 -0
  29. package/dist/model-provider-fixtures.d.ts.map +1 -0
  30. package/dist/polling.d.ts +1 -1
  31. package/dist/polling.d.ts.map +1 -1
  32. package/dist/process-driver.d.ts +10 -0
  33. package/dist/process-driver.d.ts.map +1 -0
  34. package/dist/server-extension-test-harness.d.ts +17 -2
  35. package/dist/server-extension-test-harness.d.ts.map +1 -1
  36. package/dist/stub-worker-entry.js +9 -5
  37. package/dist/stub-worker-entry.js.map +1 -1
  38. package/dist/worker-testing/in-process-worker-spawn.d.ts +5 -0
  39. package/dist/worker-testing/in-process-worker-spawn.d.ts.map +1 -1
  40. package/dist/worker-testing/index.d.ts +1 -1
  41. package/dist/worker-testing/index.d.ts.map +1 -1
  42. package/dist/worker-testing/index.js +371 -7
  43. package/dist/worker-testing/index.js.map +1 -1
  44. package/dist/worker-testing/stub-pi-tree-handle.d.ts +19 -1
  45. package/dist/worker-testing/stub-pi-tree-handle.d.ts.map +1 -1
  46. package/dist/worker-testing/worker-start-payload.d.ts.map +1 -1
  47. package/package.json +14 -9
  48. package/src/compact-process-detail-fixture.ts +28 -2
  49. package/src/http-launch.ts +87 -0
  50. package/src/index.ts +9 -5
  51. package/src/integration.ts +1 -0
  52. package/src/local-git.ts +349 -0
  53. package/src/model-provider-fixtures.ts +23 -0
  54. package/src/polling.ts +2 -2
  55. package/src/process-driver.ts +57 -0
  56. package/src/server-extension-test-harness.ts +42 -5
  57. package/src/worker-testing/in-process-worker-spawn.ts +22 -2
  58. package/src/worker-testing/index.ts +5 -1
  59. package/src/worker-testing/stub-pi-tree-handle.ts +221 -20
  60. package/src/worker-testing/worker-start-payload.ts +1 -0
  61. package/dist/chunk-KIDBCGNW.js.map +0 -1
  62. package/dist/chunk-QFCJV2VA.js.map +0 -1
  63. package/dist/chunk-R4KVUGWR.js.map +0 -1
  64. package/dist/chunk-ST2C4VKX.js.map +0 -1
  65. package/dist/compact-process-detail-fixture.js +0 -73
  66. package/dist/compact-process-detail-fixture.js.map +0 -1
  67. package/dist/fakes/fake-git-ops.js +0 -101
  68. package/dist/fakes/fake-git-ops.js.map +0 -1
  69. package/dist/fakes/fake-llm.js +0 -27
  70. package/dist/fakes/fake-llm.js.map +0 -1
  71. package/dist/in-process-worker.js +0 -2
  72. package/dist/in-process-worker.js.map +0 -1
  73. package/dist/integration-harness.js +0 -38
  74. package/dist/integration-harness.js.map +0 -1
  75. package/dist/polling.js +0 -14
  76. package/dist/polling.js.map +0 -1
  77. package/dist/question-fixtures.js +0 -26
  78. package/dist/question-fixtures.js.map +0 -1
  79. package/dist/server-extension-test-harness.js +0 -169
  80. package/dist/server-extension-test-harness.js.map +0 -1
  81. package/dist/test-app.js +0 -47
  82. package/dist/test-app.js.map +0 -1
  83. package/dist/worker-testing/in-process-worker-spawn.js +0 -61
  84. package/dist/worker-testing/in-process-worker-spawn.js.map +0 -1
  85. package/dist/worker-testing/ipc-harness.d.ts +0 -11
  86. package/dist/worker-testing/ipc-harness.d.ts.map +0 -1
  87. package/dist/worker-testing/ipc-harness.js +0 -17
  88. package/dist/worker-testing/ipc-harness.js.map +0 -1
  89. package/dist/worker-testing/schema-driven-stub-pi.js +0 -65
  90. package/dist/worker-testing/schema-driven-stub-pi.js.map +0 -1
  91. package/dist/worker-testing/stub-pi-controls.js +0 -10
  92. package/dist/worker-testing/stub-pi-controls.js.map +0 -1
  93. package/dist/worker-testing/stub-pi-tree-handle.js +0 -515
  94. package/dist/worker-testing/stub-pi-tree-handle.js.map +0 -1
  95. package/dist/worker-testing/worker-runtime-harness.js +0 -231
  96. package/dist/worker-testing/worker-runtime-harness.js.map +0 -1
  97. package/dist/worker-testing/worker-start-payload.js +0 -101
  98. package/dist/worker-testing/worker-start-payload.js.map +0 -1
  99. package/dist/workspace-source-aliases.d.ts +0 -6
  100. package/dist/workspace-source-aliases.d.ts.map +0 -1
  101. package/dist/workspace-source-aliases.js +0 -126
  102. package/dist/workspace-source-aliases.js.map +0 -1
  103. package/src/worker-testing/ipc-harness.ts +0 -19
  104. package/src/workspace-source-aliases.ts +0 -171
@@ -1,171 +0,0 @@
1
- import { existsSync, readdirSync, readFileSync } from "node:fs";
2
- import path from "node:path";
3
-
4
- interface RootPackageJson {
5
- workspaces?: string[] | { packages?: string[] };
6
- }
7
-
8
- interface WorkspacePackageJson {
9
- name?: string;
10
- exports?: unknown;
11
- }
12
-
13
- interface JsonRecord {
14
- [key: string]: unknown;
15
- }
16
-
17
- export interface WorkspaceSourceAlias {
18
- find: RegExp;
19
- replacement: string;
20
- }
21
-
22
- export function buildWorkspaceSourceAliases(
23
- rootDir: string,
24
- additionalPackageDirs: readonly string[] = [],
25
- ): WorkspaceSourceAlias[] {
26
- const packageDirs = [
27
- ...new Set([...listWorkspacePackageDirs(rootDir), ...additionalPackageDirs]),
28
- ];
29
- const aliases = packageDirs.flatMap((packageDir) => buildAliasesForPackage(packageDir));
30
-
31
- return aliases.sort((left, right) => {
32
- const lengthDelta = right.find.source.length - left.find.source.length;
33
- if (lengthDelta !== 0) {
34
- return lengthDelta;
35
- }
36
- return left.find.source.localeCompare(right.find.source);
37
- });
38
- }
39
-
40
- function buildAliasesForPackage(packageDir: string): WorkspaceSourceAlias[] {
41
- const packageJson = readJson<WorkspacePackageJson>(path.join(packageDir, "package.json"));
42
- if (!packageJson.name) {
43
- return [];
44
- }
45
-
46
- return listPackageExportTargets(packageJson.name, packageJson.exports).flatMap(
47
- ({ specifier, importTarget }) => {
48
- const replacement = resolveSourceFile(packageDir, importTarget);
49
- if (!replacement) {
50
- return [];
51
- }
52
- return [{ find: createExactSpecifierPattern(specifier), replacement }];
53
- },
54
- );
55
- }
56
-
57
- function listWorkspacePackageDirs(rootDir: string): string[] {
58
- const rootPackageJson = readJson<RootPackageJson>(path.join(rootDir, "package.json"));
59
- const workspacePatterns = Array.isArray(rootPackageJson.workspaces)
60
- ? rootPackageJson.workspaces
61
- : (rootPackageJson.workspaces?.packages ?? []);
62
-
63
- return workspacePatterns
64
- .flatMap((pattern) => expandWorkspacePattern(rootDir, pattern))
65
- .filter((packageDir, index, dirs) => dirs.indexOf(packageDir) === index)
66
- .sort((left, right) => left.localeCompare(right));
67
- }
68
-
69
- function expandWorkspacePattern(rootDir: string, pattern: string): string[] {
70
- if (pattern.endsWith("/*")) {
71
- const baseDir = path.join(rootDir, pattern.slice(0, -2));
72
- if (!existsSync(baseDir)) {
73
- return [];
74
- }
75
- return readdirSync(baseDir, { withFileTypes: true })
76
- .filter((entry) => entry.isDirectory())
77
- .map((entry) => path.join(baseDir, entry.name))
78
- .filter((packageDir) => existsSync(path.join(packageDir, "package.json")));
79
- }
80
-
81
- const packageDir = path.join(rootDir, pattern);
82
- return existsSync(path.join(packageDir, "package.json")) ? [packageDir] : [];
83
- }
84
-
85
- function listPackageExportTargets(
86
- packageName: string,
87
- exportsField: unknown,
88
- ): Array<{ specifier: string; importTarget: string }> {
89
- if (!exportsField) {
90
- return [];
91
- }
92
-
93
- if (isPackageSubpathExportMap(exportsField)) {
94
- return Object.entries(exportsField).flatMap(([subpath, exportValue]) => {
95
- const importTarget = resolveImportTarget(exportValue);
96
- if (!importTarget) {
97
- return [];
98
- }
99
- const specifier = subpath === "." ? packageName : `${packageName}/${subpath.slice(2)}`;
100
- return [{ specifier, importTarget }];
101
- });
102
- }
103
-
104
- const importTarget = resolveImportTarget(exportsField);
105
- return importTarget ? [{ specifier: packageName, importTarget }] : [];
106
- }
107
-
108
- function isPackageSubpathExportMap(value: unknown): value is JsonRecord {
109
- if (!isJsonRecord(value)) {
110
- return false;
111
- }
112
- return Object.keys(value).some((key) => key === "." || key.startsWith("./"));
113
- }
114
-
115
- function resolveImportTarget(exportValue: unknown): string | null {
116
- if (typeof exportValue === "string") {
117
- return exportValue;
118
- }
119
- if (!isJsonRecord(exportValue)) {
120
- return null;
121
- }
122
- if (typeof exportValue.import === "string") {
123
- return exportValue.import;
124
- }
125
- if (typeof exportValue.default === "string") {
126
- return exportValue.default;
127
- }
128
- return null;
129
- }
130
-
131
- function resolveSourceFile(packageDir: string, importTarget: string): string | null {
132
- const normalizedTarget = importTarget.startsWith("./") ? importTarget.slice(2) : importTarget;
133
- for (const candidate of buildSourceCandidates(normalizedTarget)) {
134
- const absoluteCandidate = path.join(packageDir, candidate);
135
- if (existsSync(absoluteCandidate)) {
136
- return absoluteCandidate;
137
- }
138
- }
139
- return null;
140
- }
141
-
142
- function buildSourceCandidates(importTarget: string): string[] {
143
- const srcTarget = importTarget.startsWith("dist/")
144
- ? `src/${importTarget.slice("dist/".length)}`
145
- : importTarget;
146
- const extensionlessTarget = srcTarget.replace(/\.(?:[cm]?js)$/, "");
147
-
148
- return [
149
- `${extensionlessTarget}.ts`,
150
- `${extensionlessTarget}.tsx`,
151
- `${extensionlessTarget}.mts`,
152
- `${extensionlessTarget}.cts`,
153
- srcTarget,
154
- ];
155
- }
156
-
157
- function createExactSpecifierPattern(specifier: string): RegExp {
158
- return new RegExp(`^${escapeRegExp(specifier)}$`);
159
- }
160
-
161
- function escapeRegExp(value: string): string {
162
- return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
163
- }
164
-
165
- function isJsonRecord(value: unknown): value is JsonRecord {
166
- return typeof value === "object" && value !== null && !Array.isArray(value);
167
- }
168
-
169
- function readJson<T>(filePath: string): T {
170
- return JSON.parse(readFileSync(filePath, "utf8")) as T;
171
- }