@kevlns/u-cli-mod 0.2.4 → 0.3.1
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/AGENTS.md +228 -199
- package/LICENSE +2 -2
- package/README.md +36 -133
- package/dist/cli.js +1 -1
- package/dist/runIdPatch.d.ts +8 -0
- package/dist/runIdPatch.js +591 -0
- package/dist/transform.js +13 -0
- package/docs/SELF_HOSTED_RUNNER.md +100 -0
- package/docs/documentation.md +24 -0
- package/package.json +8 -9
- package/routes/2022.3.59f1c1.json +1 -1
- package/routes/2022.3.62f3c1.json +1 -1
- package/routes/expected-tree/2022.3.59f1c1.json +4 -4
- package/routes/expected-tree/2022.3.62f3c1.json +4 -4
- package/v-cli.plugin.json +238 -219
|
@@ -0,0 +1,591 @@
|
|
|
1
|
+
import { CliError } from './errors.js';
|
|
2
|
+
/**
|
|
3
|
+
* runId protocol patch (patchVersion 3): cross-domain-reload task identity for
|
|
4
|
+
* the test pipeline and recompile status, consumed by v-cli execution handles.
|
|
5
|
+
*
|
|
6
|
+
* Semantics (design of record: v-cli .vant/docs/spec/phase-a-identity-matrix.md §3):
|
|
7
|
+
* - run_tests --async_tests assigns a runId (GUID "N"), persisted in the request
|
|
8
|
+
* file and echoed in the response (TestExecutionResponse.RunId); every status
|
|
9
|
+
* payload written for that run (completed/error/cancelled) carries the runId.
|
|
10
|
+
* - test_status --run_id <id>: correlated read. Request file with matching id ->
|
|
11
|
+
* running; status file with matching id -> its content; anything else ->
|
|
12
|
+
* {"status":"unknown_run"} — NEVER another run's record, never the latest run.
|
|
13
|
+
* - cancel_tests --run_id <id>: directed cancel. Mismatched or no active run ->
|
|
14
|
+
* {"status":"unknown_run"|"no_active_run"} with ZERO side effects (the status
|
|
15
|
+
* file of another run is never overwritten). Matching id -> current cancel
|
|
16
|
+
* behaviour, with runId recorded in the cancelled payload.
|
|
17
|
+
* - recompile assigns a runId; engine compilation events propagate it to the
|
|
18
|
+
* terminal payload. Engine-spontaneous compiles (no pending command id) write
|
|
19
|
+
* runId:null. recompile_status --run_id mirrors the correlated-read semantics.
|
|
20
|
+
*
|
|
21
|
+
* All patches are exact-anchor string replacements over the pinned upstream
|
|
22
|
+
* bytes; a missing anchor is a hard error (the upstream revision moved), never
|
|
23
|
+
* a silent skip. Output is LF-normalized like the other patches.
|
|
24
|
+
*/
|
|
25
|
+
function applyPatches(source, name, sentinel, pairs) {
|
|
26
|
+
let s = source.toString('utf8');
|
|
27
|
+
if (s.includes(sentinel)) {
|
|
28
|
+
// Already patched: idempotent no-op (normalized passthrough).
|
|
29
|
+
return Buffer.from(s.replace(/\r\n/g, '\n'), 'utf8');
|
|
30
|
+
}
|
|
31
|
+
for (const [anchor, replacement] of pairs) {
|
|
32
|
+
if (!s.includes(anchor)) {
|
|
33
|
+
throw new CliError(`${name} 缺少锚点(上游修订已变化?): ${JSON.stringify(anchor.slice(0, 80))}…`);
|
|
34
|
+
}
|
|
35
|
+
s = s.replace(anchor, replacement);
|
|
36
|
+
}
|
|
37
|
+
return Buffer.from(s.replace(/\r\n/g, '\n'), 'utf8');
|
|
38
|
+
}
|
|
39
|
+
export const testCommandsPatches = [
|
|
40
|
+
[
|
|
41
|
+
` [CliCommand("test_status", "Get status of running async test execution", MainThreadRequired = false, Tags = new[] { "tests" })]
|
|
42
|
+
public static string GetTestStatus()
|
|
43
|
+
{
|
|
44
|
+
var status = PipelineTestRunner.GetTestStatus();
|
|
45
|
+
return status ?? "{\\"status\\":\\"no_tests\\",\\"message\\":\\"No test run in progress\\"}";
|
|
46
|
+
}`,
|
|
47
|
+
` [CliCommand("test_status", "Get status of running async test execution; optional run_id for correlated query", MainThreadRequired = false, Tags = new[] { "tests" })]
|
|
48
|
+
public static string GetTestStatus(
|
|
49
|
+
[CliArg("run_id", "Optional run id from run_tests --async_tests: return only that run's record; unknown_run otherwise (never another run's record)")] string runId = null)
|
|
50
|
+
{
|
|
51
|
+
var status = PipelineTestRunner.GetTestStatus(string.IsNullOrEmpty(runId) ? null : runId.Trim());
|
|
52
|
+
return status ?? "{\\"status\\":\\"no_tests\\",\\"message\\":\\"No test run in progress\\"}";
|
|
53
|
+
}`,
|
|
54
|
+
],
|
|
55
|
+
[
|
|
56
|
+
` [CliCommand("cancel_tests", "Cancel running test execution", MainThreadRequired = true, Tags = new[] { "tests" })]
|
|
57
|
+
public static object CancelTests()
|
|
58
|
+
{
|
|
59
|
+
return PipelineTestRunner.CancelTests();
|
|
60
|
+
}`,
|
|
61
|
+
` [CliCommand("cancel_tests", "Cancel running test execution; optional run_id for directed cancel (mismatch has no side effects)", MainThreadRequired = true, Tags = new[] { "tests" })]
|
|
62
|
+
public static object CancelTests(
|
|
63
|
+
[CliArg("run_id", "Optional run id to cancel; unknown_run/no_active_run when it is not the active run, leaving everything untouched")] string runId = null)
|
|
64
|
+
{
|
|
65
|
+
return PipelineTestRunner.CancelTests(string.IsNullOrEmpty(runId) ? null : runId.Trim());
|
|
66
|
+
}`,
|
|
67
|
+
],
|
|
68
|
+
];
|
|
69
|
+
export function patchTestCommands(bytes) {
|
|
70
|
+
return applyPatches(bytes, 'TestCommands.cs', 'CliArg("run_id"', testCommandsPatches);
|
|
71
|
+
}
|
|
72
|
+
export const pipelineTestRunnerPatches = [
|
|
73
|
+
// 1) request model carries the run id
|
|
74
|
+
[
|
|
75
|
+
` public bool includeExplicit;
|
|
76
|
+
public bool isSync;
|
|
77
|
+
}`,
|
|
78
|
+
` public bool includeExplicit;
|
|
79
|
+
public bool isSync;
|
|
80
|
+
public string runId;
|
|
81
|
+
}`,
|
|
82
|
+
],
|
|
83
|
+
// 2) async start: assign run id, persist it, echo it, thread it through
|
|
84
|
+
[
|
|
85
|
+
` // Save request to disk (survives domain reloads for PlayMode)
|
|
86
|
+
var request = new TestRequest
|
|
87
|
+
{
|
|
88
|
+
filter = filter,
|
|
89
|
+
filterType = filterType,
|
|
90
|
+
mode = testMode.ToString(),
|
|
91
|
+
includeExplicit = includeExplicit,
|
|
92
|
+
isSync = false
|
|
93
|
+
};
|
|
94
|
+
File.WriteAllText(TestRequestFile, JsonConvert.SerializeObject(request));`,
|
|
95
|
+
` // Save request to disk (survives domain reloads for PlayMode)
|
|
96
|
+
var runId = Guid.NewGuid().ToString("N");
|
|
97
|
+
var request = new TestRequest
|
|
98
|
+
{
|
|
99
|
+
filter = filter,
|
|
100
|
+
filterType = filterType,
|
|
101
|
+
mode = testMode.ToString(),
|
|
102
|
+
includeExplicit = includeExplicit,
|
|
103
|
+
isSync = false,
|
|
104
|
+
runId = runId
|
|
105
|
+
};
|
|
106
|
+
File.WriteAllText(TestRequestFile, JsonConvert.SerializeObject(request));`,
|
|
107
|
+
],
|
|
108
|
+
[
|
|
109
|
+
` StartAsyncTestExecution(testMode, filter, filterType, includeExplicit);`,
|
|
110
|
+
` StartAsyncTestExecution(testMode, filter, filterType, includeExplicit, runId);`,
|
|
111
|
+
],
|
|
112
|
+
[
|
|
113
|
+
` Result = "running",
|
|
114
|
+
StatusPath = TestStatusFile,
|
|
115
|
+
Mode = testMode.ToString(),`,
|
|
116
|
+
` Result = "running",
|
|
117
|
+
RunId = runId,
|
|
118
|
+
StatusPath = TestStatusFile,
|
|
119
|
+
Mode = testMode.ToString(),`,
|
|
120
|
+
],
|
|
121
|
+
// 3) async execution thread: run id into every status write
|
|
122
|
+
[
|
|
123
|
+
` private static void StartAsyncTestExecution(TestMode testMode, string filter, string filterType, bool includeExplicit)
|
|
124
|
+
{`,
|
|
125
|
+
` private static void StartAsyncTestExecution(TestMode testMode, string filter, string filterType, bool includeExplicit, string runId)
|
|
126
|
+
{`,
|
|
127
|
+
],
|
|
128
|
+
[
|
|
129
|
+
` // Async completion: write results for pollers. Set once, never overwritten.
|
|
130
|
+
collector.OnRunFinished = () =>
|
|
131
|
+
{
|
|
132
|
+
WriteCompletedResults(collector);
|
|
133
|
+
RestoreLiveServerIfDisrupted(); // B2: self-heal if a test broke the live server.
|
|
134
|
+
CleanupRequestFile();
|
|
135
|
+
UnregisterCollector(api, collector);
|
|
136
|
+
};`,
|
|
137
|
+
` // Async completion: write results for pollers. Set once, never overwritten.
|
|
138
|
+
collector.OnRunFinished = () =>
|
|
139
|
+
{
|
|
140
|
+
WriteCompletedResults(collector, runId);
|
|
141
|
+
RestoreLiveServerIfDisrupted(); // B2: self-heal if a test broke the live server.
|
|
142
|
+
CleanupRequestFile();
|
|
143
|
+
UnregisterCollector(api, collector);
|
|
144
|
+
};`,
|
|
145
|
+
],
|
|
146
|
+
[
|
|
147
|
+
` if (testNames.Count == 0)
|
|
148
|
+
{
|
|
149
|
+
WriteStatusFile(new
|
|
150
|
+
{
|
|
151
|
+
status = "completed",
|
|
152
|
+
duration = 0.0,
|
|
153
|
+
summary = new { total = 0, passed = 0, failed = 0, skipped = 0, inconclusive = 0 },
|
|
154
|
+
results = new object[0]
|
|
155
|
+
});`,
|
|
156
|
+
` if (testNames.Count == 0)
|
|
157
|
+
{
|
|
158
|
+
WriteStatusFile(new
|
|
159
|
+
{
|
|
160
|
+
status = "completed",
|
|
161
|
+
runId = runId,
|
|
162
|
+
duration = 0.0,
|
|
163
|
+
summary = new { total = 0, passed = 0, failed = 0, skipped = 0, inconclusive = 0 },
|
|
164
|
+
results = new object[0]
|
|
165
|
+
});`,
|
|
166
|
+
],
|
|
167
|
+
[
|
|
168
|
+
` Debug.LogError($"[PipelineTestRunner] Async run setup error: {ex.Message}");
|
|
169
|
+
WriteStatusFile(new { status = "error", message = ex.Message });`,
|
|
170
|
+
` Debug.LogError($"[PipelineTestRunner] Async run setup error: {ex.Message}");
|
|
171
|
+
WriteStatusFile(new { status = "error", runId = runId, message = ex.Message });`,
|
|
172
|
+
],
|
|
173
|
+
[
|
|
174
|
+
` Debug.LogError($"[PipelineTestRunner] Async execution error: {ex.Message}");
|
|
175
|
+
WriteStatusFile(new { status = "error", message = ex.Message });`,
|
|
176
|
+
` Debug.LogError($"[PipelineTestRunner] Async execution error: {ex.Message}");
|
|
177
|
+
WriteStatusFile(new { status = "error", runId = runId, message = ex.Message });`,
|
|
178
|
+
],
|
|
179
|
+
// 4) post-reload reattach: recover the run id from the request file
|
|
180
|
+
[
|
|
181
|
+
` private static void ReattachResultCollector()
|
|
182
|
+
{`,
|
|
183
|
+
` private static void ReattachResultCollector(string runId)
|
|
184
|
+
{`,
|
|
185
|
+
],
|
|
186
|
+
[
|
|
187
|
+
` collector.OnRunFinished = () =>
|
|
188
|
+
{
|
|
189
|
+
WriteCompletedResults(collector);
|
|
190
|
+
RestoreLiveServerIfDisrupted();
|
|
191
|
+
CleanupRequestFile();
|
|
192
|
+
UnregisterCollector(api, collector);
|
|
193
|
+
};`,
|
|
194
|
+
` collector.OnRunFinished = () =>
|
|
195
|
+
{
|
|
196
|
+
WriteCompletedResults(collector, runId);
|
|
197
|
+
RestoreLiveServerIfDisrupted();
|
|
198
|
+
CleanupRequestFile();
|
|
199
|
+
UnregisterCollector(api, collector);
|
|
200
|
+
};`,
|
|
201
|
+
],
|
|
202
|
+
[
|
|
203
|
+
` // We only need to re-register a collector — our previous one did not survive the
|
|
204
|
+
// reload — to capture the resumed run's completion. Runs on the main thread because
|
|
205
|
+
// CheckForPendingTests is invoked via EditorApplication.delayCall.
|
|
206
|
+
ReattachResultCollector();`,
|
|
207
|
+
` // We only need to re-register a collector — our previous one did not survive the
|
|
208
|
+
// reload — to capture the resumed run's completion. Runs on the main thread because
|
|
209
|
+
// CheckForPendingTests is invoked via EditorApplication.delayCall.
|
|
210
|
+
ReattachResultCollector(request.runId);`,
|
|
211
|
+
],
|
|
212
|
+
// 5) terminal report carries the run id
|
|
213
|
+
[
|
|
214
|
+
` private static void WriteCompletedResults(TestResultCollector collector)
|
|
215
|
+
{`,
|
|
216
|
+
` private static void WriteCompletedResults(TestResultCollector collector, string runId)
|
|
217
|
+
{`,
|
|
218
|
+
],
|
|
219
|
+
[
|
|
220
|
+
` var result = new
|
|
221
|
+
{
|
|
222
|
+
status = "completed",
|
|
223
|
+
duration = Math.Round(root.Duration, 2),`,
|
|
224
|
+
` var result = new
|
|
225
|
+
{
|
|
226
|
+
status = "completed",
|
|
227
|
+
runId = runId,
|
|
228
|
+
duration = Math.Round(root.Duration, 2),`,
|
|
229
|
+
],
|
|
230
|
+
// 6) correlated status read + helpers
|
|
231
|
+
[
|
|
232
|
+
` /// <summary>
|
|
233
|
+
/// Get current test status (for async mode polling)
|
|
234
|
+
/// </summary>
|
|
235
|
+
public static string GetTestStatus()
|
|
236
|
+
{
|
|
237
|
+
if (File.Exists(TestStatusFile))
|
|
238
|
+
return File.ReadAllText(TestStatusFile);
|
|
239
|
+
if (File.Exists(TestRequestFile))
|
|
240
|
+
return JsonConvert.SerializeObject(new { status = "running" });
|
|
241
|
+
return null;
|
|
242
|
+
}`,
|
|
243
|
+
` private class RunIdEnvelope
|
|
244
|
+
{
|
|
245
|
+
public string runId { get; set; }
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
private static string RequestRunId()
|
|
249
|
+
{
|
|
250
|
+
try
|
|
251
|
+
{
|
|
252
|
+
if (!File.Exists(TestRequestFile)) return null;
|
|
253
|
+
var request = JsonConvert.DeserializeObject<TestRequest>(File.ReadAllText(TestRequestFile));
|
|
254
|
+
return string.IsNullOrEmpty(request?.runId) ? null : request.runId;
|
|
255
|
+
}
|
|
256
|
+
catch
|
|
257
|
+
{
|
|
258
|
+
return null;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
private static string StatusRunId()
|
|
263
|
+
{
|
|
264
|
+
try
|
|
265
|
+
{
|
|
266
|
+
if (!File.Exists(TestStatusFile)) return null;
|
|
267
|
+
var envelope = JsonConvert.DeserializeObject<RunIdEnvelope>(File.ReadAllText(TestStatusFile));
|
|
268
|
+
return string.IsNullOrEmpty(envelope?.runId) ? null : envelope.runId;
|
|
269
|
+
}
|
|
270
|
+
catch
|
|
271
|
+
{
|
|
272
|
+
return null;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/// <summary>
|
|
277
|
+
/// Get current test status (for async mode polling). With runId: correlated
|
|
278
|
+
/// read — only the requested run's record is returned; unknown_run otherwise.
|
|
279
|
+
/// </summary>
|
|
280
|
+
public static string GetTestStatus(string runId = null)
|
|
281
|
+
{
|
|
282
|
+
if (runId == null)
|
|
283
|
+
{
|
|
284
|
+
if (File.Exists(TestStatusFile))
|
|
285
|
+
return File.ReadAllText(TestStatusFile);
|
|
286
|
+
if (File.Exists(TestRequestFile))
|
|
287
|
+
return JsonConvert.SerializeObject(new { status = "running" });
|
|
288
|
+
return null;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
if (File.Exists(TestRequestFile) && RequestRunId() == runId)
|
|
292
|
+
return JsonConvert.SerializeObject(new { status = "running", runId = runId });
|
|
293
|
+
|
|
294
|
+
if (File.Exists(TestStatusFile))
|
|
295
|
+
{
|
|
296
|
+
if (StatusRunId() == runId)
|
|
297
|
+
return File.ReadAllText(TestStatusFile);
|
|
298
|
+
return JsonConvert.SerializeObject(new
|
|
299
|
+
{
|
|
300
|
+
status = "unknown_run",
|
|
301
|
+
requestedRunId = runId,
|
|
302
|
+
message = "Requested run is not the tracked run; refusing to return another run's record."
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
return JsonConvert.SerializeObject(new
|
|
307
|
+
{
|
|
308
|
+
status = "unknown_run",
|
|
309
|
+
requestedRunId = runId,
|
|
310
|
+
message = "No record for the requested run id."
|
|
311
|
+
});
|
|
312
|
+
}`,
|
|
313
|
+
],
|
|
314
|
+
// 7) error terminal payloads carry the run id (spec: ALL status payloads of a run carry runId)
|
|
315
|
+
[
|
|
316
|
+
` if (!collector.IsComplete)
|
|
317
|
+
{
|
|
318
|
+
WriteStatusFile(new { status = "error", message = "Tests did not complete" });
|
|
319
|
+
return;
|
|
320
|
+
}`,
|
|
321
|
+
` if (!collector.IsComplete)
|
|
322
|
+
{
|
|
323
|
+
WriteStatusFile(new { status = "error", runId = runId, message = "Tests did not complete" });
|
|
324
|
+
return;
|
|
325
|
+
}`,
|
|
326
|
+
],
|
|
327
|
+
[
|
|
328
|
+
` catch (Exception ex)
|
|
329
|
+
{
|
|
330
|
+
Debug.LogError($"[PipelineTestRunner] Failed to write results: {ex.Message}");
|
|
331
|
+
WriteStatusFile(new { status = "error", message = ex.Message });
|
|
332
|
+
}`,
|
|
333
|
+
` catch (Exception ex)
|
|
334
|
+
{
|
|
335
|
+
Debug.LogError($"[PipelineTestRunner] Failed to write results: {ex.Message}");
|
|
336
|
+
WriteStatusFile(new { status = "error", runId = runId, message = ex.Message });
|
|
337
|
+
}`,
|
|
338
|
+
],
|
|
339
|
+
[
|
|
340
|
+
` catch (Exception ex)
|
|
341
|
+
{
|
|
342
|
+
Debug.LogError($"[PipelineTestRunner] Failed to reattach result collector: {ex.Message}");
|
|
343
|
+
WriteStatusFile(new { status = "error", message = ex.Message });
|
|
344
|
+
CleanupRequestFile();
|
|
345
|
+
UnregisterCollector(api, collector);
|
|
346
|
+
}`,
|
|
347
|
+
` catch (Exception ex)
|
|
348
|
+
{
|
|
349
|
+
Debug.LogError($"[PipelineTestRunner] Failed to reattach result collector: {ex.Message}");
|
|
350
|
+
WriteStatusFile(new { status = "error", runId = runId, message = ex.Message });
|
|
351
|
+
CleanupRequestFile();
|
|
352
|
+
UnregisterCollector(api, collector);
|
|
353
|
+
}`,
|
|
354
|
+
],
|
|
355
|
+
// 7) directed cancel: mismatch has zero side effects
|
|
356
|
+
[
|
|
357
|
+
` public static object CancelTests()
|
|
358
|
+
{
|
|
359
|
+
if (m_ActiveCollector == null && !File.Exists(TestRequestFile) && !File.Exists(TestStatusFile))
|
|
360
|
+
return new { status = "no_tests", message = "No test run in progress." };
|
|
361
|
+
|
|
362
|
+
bool wasPlayMode = false;
|
|
363
|
+
try
|
|
364
|
+
{
|
|
365
|
+
if (File.Exists(TestRequestFile))
|
|
366
|
+
{
|
|
367
|
+
var json = File.ReadAllText(TestRequestFile);
|
|
368
|
+
wasPlayMode = json.Contains("PlayMode");
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
catch { }
|
|
372
|
+
|
|
373
|
+
InvalidatePreviousRun();
|
|
374
|
+
WriteStatusFile(new { status = "cancelled", message = "Test run cancelled." });`,
|
|
375
|
+
` public static object CancelTests(string runId = null)
|
|
376
|
+
{
|
|
377
|
+
var hasActiveRun = File.Exists(TestRequestFile);
|
|
378
|
+
// Read the request file ONCE: the guard and the cancelled payload must agree even if the
|
|
379
|
+
// run completes (and deletes the request file) between the two reads.
|
|
380
|
+
var activeRunId = hasActiveRun ? RequestRunId() : null;
|
|
381
|
+
if (runId != null)
|
|
382
|
+
{
|
|
383
|
+
if (!hasActiveRun)
|
|
384
|
+
return new
|
|
385
|
+
{
|
|
386
|
+
status = "no_active_run",
|
|
387
|
+
requestedRunId = runId,
|
|
388
|
+
message = "No test run in progress; nothing was touched."
|
|
389
|
+
};
|
|
390
|
+
if (activeRunId != runId)
|
|
391
|
+
return new
|
|
392
|
+
{
|
|
393
|
+
status = "unknown_run",
|
|
394
|
+
requestedRunId = runId,
|
|
395
|
+
message = "Requested run is not the active run; no cancellation was performed."
|
|
396
|
+
};
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
if (m_ActiveCollector == null && !File.Exists(TestRequestFile) && !File.Exists(TestStatusFile))
|
|
400
|
+
return new { status = "no_tests", message = "No test run in progress." };
|
|
401
|
+
|
|
402
|
+
bool wasPlayMode = false;
|
|
403
|
+
var cancelledRunId = activeRunId;
|
|
404
|
+
try
|
|
405
|
+
{
|
|
406
|
+
if (File.Exists(TestRequestFile))
|
|
407
|
+
{
|
|
408
|
+
var json = File.ReadAllText(TestRequestFile);
|
|
409
|
+
wasPlayMode = json.Contains("PlayMode");
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
catch { }
|
|
413
|
+
|
|
414
|
+
InvalidatePreviousRun();
|
|
415
|
+
WriteStatusFile(new { status = "cancelled", runId = cancelledRunId, message = "Test run cancelled." });`,
|
|
416
|
+
],
|
|
417
|
+
];
|
|
418
|
+
export function patchPipelineTestRunner(bytes) {
|
|
419
|
+
return applyPatches(bytes, 'PipelineTestRunner.cs', 'requestedRunId', pipelineTestRunnerPatches);
|
|
420
|
+
}
|
|
421
|
+
export const recompileCommandPatches = [
|
|
422
|
+
// pending command run id survives the trigger->engine-event handoff in-process
|
|
423
|
+
[
|
|
424
|
+
` static readonly List<string> s_Errors = new List<string>();`,
|
|
425
|
+
` static readonly List<string> s_Errors = new List<string>();
|
|
426
|
+
|
|
427
|
+
// Run id assigned by the recompile command (patchVersion 3). Engine events
|
|
428
|
+
// propagate it into the terminal payload; engine-spontaneous compiles
|
|
429
|
+
// (no pending id) write runId:null. Never persists across domain reloads —
|
|
430
|
+
// by design: the triggering request cannot survive the reload anyway.
|
|
431
|
+
static string s_PendingRunId;`,
|
|
432
|
+
],
|
|
433
|
+
[
|
|
434
|
+
` if (focus)
|
|
435
|
+
s_FocusAction();
|
|
436
|
+
|
|
437
|
+
WriteStatus("triggered", false, null);
|
|
438
|
+
|
|
439
|
+
// Trigger asset import + compilation.
|
|
440
|
+
AssetDatabase.Refresh();
|
|
441
|
+
|
|
442
|
+
if (EditorApplication.isCompiling)
|
|
443
|
+
{
|
|
444
|
+
// compilationStarted has written "compiling"; a domain reload will follow on success.
|
|
445
|
+
return new { status = "compiling", message = "Recompilation started. Poll recompile_status until completed." };
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
// Nothing needed recompilation.
|
|
449
|
+
WriteStatus("up_to_date", false, null);
|
|
450
|
+
return new { status = "up_to_date", message = "No scripts needed recompilation." };`,
|
|
451
|
+
` if (focus)
|
|
452
|
+
s_FocusAction();
|
|
453
|
+
|
|
454
|
+
var runId = Guid.NewGuid().ToString("N");
|
|
455
|
+
s_PendingRunId = runId;
|
|
456
|
+
WriteStatus("triggered", runId, false, null);
|
|
457
|
+
|
|
458
|
+
// Trigger asset import + compilation.
|
|
459
|
+
AssetDatabase.Refresh();
|
|
460
|
+
|
|
461
|
+
if (EditorApplication.isCompiling)
|
|
462
|
+
{
|
|
463
|
+
// compilationStarted has written "compiling"; a domain reload will follow on success.
|
|
464
|
+
return new { status = "compiling", runId = runId, message = "Recompilation started. Poll recompile_status until completed." };
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
// Nothing needed recompilation. Terminal state reached without engine events:
|
|
468
|
+
// clear the pending id so a later engine-spontaneous compile is NOT attributed to this run.
|
|
469
|
+
WriteStatus("up_to_date", runId, false, null);
|
|
470
|
+
s_PendingRunId = null;
|
|
471
|
+
return new { status = "up_to_date", runId = runId, message = "No scripts needed recompilation." };`,
|
|
472
|
+
],
|
|
473
|
+
[
|
|
474
|
+
` [CliCommand("recompile_status", "Get the status of the last recompile: idle | triggered | compiling | completed | up_to_date.", MainThreadRequired = false, Tags = new[] { "scripts/compile" })]
|
|
475
|
+
public static string RecompileStatus()
|
|
476
|
+
{
|
|
477
|
+
if (File.Exists(StatusFile))
|
|
478
|
+
return File.ReadAllText(StatusFile);
|
|
479
|
+
return "{\\"status\\":\\"idle\\"}";
|
|
480
|
+
}`,
|
|
481
|
+
` private class StatusEnvelope
|
|
482
|
+
{
|
|
483
|
+
public string runId { get; set; }
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
[CliCommand("recompile_status", "Get the status of the last recompile: idle | triggered | compiling | completed | up_to_date; optional run_id for correlated query", MainThreadRequired = false, Tags = new[] { "scripts/compile" })]
|
|
487
|
+
public static string RecompileStatus(
|
|
488
|
+
[CliArg("run_id", "Optional run id from the recompile response: return only that run's terminal payload; unknown_run otherwise (null runId = engine-spontaneous compile)")] string runId = null)
|
|
489
|
+
{
|
|
490
|
+
var requested = string.IsNullOrEmpty(runId) ? null : runId.Trim();
|
|
491
|
+
if (requested == null)
|
|
492
|
+
{
|
|
493
|
+
if (File.Exists(StatusFile))
|
|
494
|
+
return File.ReadAllText(StatusFile);
|
|
495
|
+
return "{\\"status\\":\\"idle\\"}";
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
if (File.Exists(StatusFile))
|
|
499
|
+
{
|
|
500
|
+
string recorded;
|
|
501
|
+
try
|
|
502
|
+
{
|
|
503
|
+
recorded = JsonConvert.DeserializeObject<StatusEnvelope>(File.ReadAllText(StatusFile))?.runId;
|
|
504
|
+
}
|
|
505
|
+
catch
|
|
506
|
+
{
|
|
507
|
+
recorded = null;
|
|
508
|
+
}
|
|
509
|
+
if (recorded == requested)
|
|
510
|
+
return File.ReadAllText(StatusFile);
|
|
511
|
+
return JsonConvert.SerializeObject(new
|
|
512
|
+
{
|
|
513
|
+
status = "unknown_run",
|
|
514
|
+
requestedRunId = requested,
|
|
515
|
+
message = "Recorded compile status belongs to another run (runId mismatch or engine-spontaneous compile); refusing to return it."
|
|
516
|
+
});
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
return JsonConvert.SerializeObject(new
|
|
520
|
+
{
|
|
521
|
+
status = "unknown_run",
|
|
522
|
+
requestedRunId = requested,
|
|
523
|
+
message = "No compile status record for the requested run id."
|
|
524
|
+
});
|
|
525
|
+
}`,
|
|
526
|
+
],
|
|
527
|
+
[
|
|
528
|
+
` static void OnCompilationStarted(object _)
|
|
529
|
+
{
|
|
530
|
+
s_Errors.Clear();
|
|
531
|
+
WriteStatus("compiling", false, null);
|
|
532
|
+
}`,
|
|
533
|
+
` static void OnCompilationStarted(object _)
|
|
534
|
+
{
|
|
535
|
+
s_Errors.Clear();
|
|
536
|
+
WriteStatus("compiling", s_PendingRunId, false, null);
|
|
537
|
+
}`,
|
|
538
|
+
],
|
|
539
|
+
[
|
|
540
|
+
` static void OnCompilationFinished(object _)
|
|
541
|
+
{
|
|
542
|
+
// Written before the domain reload, so it persists for pollers after the reload.
|
|
543
|
+
WriteStatus("completed", s_Errors.Count > 0, s_Errors.ToArray());
|
|
544
|
+
}`,
|
|
545
|
+
` static void OnCompilationFinished(object _)
|
|
546
|
+
{
|
|
547
|
+
// Written before the domain reload, so it persists for pollers after the reload.
|
|
548
|
+
WriteStatus("completed", s_PendingRunId, s_Errors.Count > 0, s_Errors.ToArray());
|
|
549
|
+
s_PendingRunId = null;
|
|
550
|
+
}`,
|
|
551
|
+
],
|
|
552
|
+
[
|
|
553
|
+
` static void WriteStatus(string status, bool failed, string[] errors)
|
|
554
|
+
{
|
|
555
|
+
try
|
|
556
|
+
{
|
|
557
|
+
var payload = new { status, failed, errors = errors ?? Array.Empty<string>() };
|
|
558
|
+
File.WriteAllText(StatusFile, JsonConvert.SerializeObject(payload));
|
|
559
|
+
}
|
|
560
|
+
catch (Exception ex)
|
|
561
|
+
{
|
|
562
|
+
Debug.LogError($"[Recompile] Failed to write status file: {ex.Message}");
|
|
563
|
+
}
|
|
564
|
+
}`,
|
|
565
|
+
` static void WriteStatus(string status, string runId, bool failed, string[] errors)
|
|
566
|
+
{
|
|
567
|
+
try
|
|
568
|
+
{
|
|
569
|
+
var payload = new { status, runId, failed, errors = errors ?? Array.Empty<string>() };
|
|
570
|
+
File.WriteAllText(StatusFile, JsonConvert.SerializeObject(payload));
|
|
571
|
+
}
|
|
572
|
+
catch (Exception ex)
|
|
573
|
+
{
|
|
574
|
+
Debug.LogError($"[Recompile] Failed to write status file: {ex.Message}");
|
|
575
|
+
}
|
|
576
|
+
}`,
|
|
577
|
+
],
|
|
578
|
+
];
|
|
579
|
+
export function patchRecompileCommand(bytes) {
|
|
580
|
+
return applyPatches(bytes, 'RecompileCommand.cs', 's_PendingRunId', recompileCommandPatches);
|
|
581
|
+
}
|
|
582
|
+
export const testExecutionResponsePatches = [
|
|
583
|
+
[
|
|
584
|
+
` public string StatusPath { get; set; } // For async mode`,
|
|
585
|
+
` public string StatusPath { get; set; } // For async mode
|
|
586
|
+
public string RunId { get; set; } // Async run correlation id (run_tests --async_tests; patchVersion 3)`,
|
|
587
|
+
],
|
|
588
|
+
];
|
|
589
|
+
export function patchTestExecutionResponse(bytes) {
|
|
590
|
+
return applyPatches(bytes, 'TestExecutionResponse.cs', 'RunId { get; set; }', testExecutionResponsePatches);
|
|
591
|
+
}
|
package/dist/transform.js
CHANGED
|
@@ -3,6 +3,7 @@ import { dirname, join, relative, sep } from 'node:path';
|
|
|
3
3
|
import { CliError } from './errors.js';
|
|
4
4
|
import { sha256Buffer, compareTree } from './integrity.js';
|
|
5
5
|
import { patchConsoleCommands } from './consolePatch.js';
|
|
6
|
+
import { patchPipelineTestRunner, patchRecompileCommand, patchTestCommands, patchTestExecutionResponse, } from './runIdPatch.js';
|
|
6
7
|
/** Files/dirs present upstream that must NOT ship in the adapted package. */
|
|
7
8
|
const REMOVE_EXACT = new Set([
|
|
8
9
|
'.attestation.p7m',
|
|
@@ -143,6 +144,18 @@ export async function transformPackage(input) {
|
|
|
143
144
|
else if (rel === 'Editor/Commands/Observability/ConsoleCommands.cs') {
|
|
144
145
|
out = patchConsoleCommands(bytes);
|
|
145
146
|
}
|
|
147
|
+
else if (rel === 'Editor/Commands/TestCommands.cs') {
|
|
148
|
+
out = patchTestCommands(bytes);
|
|
149
|
+
}
|
|
150
|
+
else if (rel === 'Editor/Testing/PipelineTestRunner.cs') {
|
|
151
|
+
out = patchPipelineTestRunner(bytes);
|
|
152
|
+
}
|
|
153
|
+
else if (rel === 'Editor/Commands/RecompileCommand.cs') {
|
|
154
|
+
out = patchRecompileCommand(bytes);
|
|
155
|
+
}
|
|
156
|
+
else if (rel === 'Runtime/Models/TestExecutionResponse.cs') {
|
|
157
|
+
out = patchTestExecutionResponse(bytes);
|
|
158
|
+
}
|
|
146
159
|
else if (DLL_META_NAMES.includes(rel.split('/').pop())) {
|
|
147
160
|
const { guid } = metaBody(bytes);
|
|
148
161
|
out = Buffer.from(`fileFormatVersion: 2\nguid: ${guid}\n${dllImporterBody}`, 'utf8');
|