owlrunkit 0.13.0 → 0.15.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.
@@ -89,6 +89,98 @@ function ensureRegularDirectory(directoryPath, label) {
89
89
  return regularDirectory(directoryPath, label);
90
90
  }
91
91
 
92
+ function verificationExecutableGate(executable) {
93
+ if (!path.isAbsolute(executable)) {
94
+ return {
95
+ valid: false,
96
+ issueCode: "verify_executable_absolute_path_required",
97
+ message: "verify executable after -- must be an absolute path.",
98
+ };
99
+ }
100
+ let stat;
101
+ try {
102
+ stat = lstatSync(executable);
103
+ } catch {
104
+ return {
105
+ valid: false,
106
+ issueCode: "verify_executable_missing",
107
+ message: "verify executable must be a regular file, not a symlink.",
108
+ };
109
+ }
110
+ if (stat.isSymbolicLink()) {
111
+ return {
112
+ valid: false,
113
+ issueCode: "verify_executable_symlink_rejected",
114
+ message: "verify executable must be a regular file, not a symlink.",
115
+ };
116
+ }
117
+ if (!stat.isFile()) {
118
+ return {
119
+ valid: false,
120
+ issueCode: "verify_executable_not_regular_file",
121
+ message: "verify executable must be a regular file, not a symlink.",
122
+ };
123
+ }
124
+ return { valid: true };
125
+ }
126
+
127
+ function recordRejectedVerificationPreflight({
128
+ workspaceRoot,
129
+ executionRoot,
130
+ runId,
131
+ verificationId,
132
+ executable,
133
+ commandArgv,
134
+ issueCode,
135
+ }) {
136
+ const preflightsRoot = path.join(executionRoot, "verification-preflights");
137
+ const realRoot = ensureRegularDirectory(
138
+ preflightsRoot,
139
+ "Verification preflight directory",
140
+ );
141
+ if (
142
+ realRoot !== path.resolve(preflightsRoot)
143
+ || !within(realpathSync(executionRoot), realRoot)
144
+ || !within(realpathSync(workspaceRoot), realRoot)
145
+ ) {
146
+ throw new Error("Verification preflight directory must remain inside the execution.");
147
+ }
148
+ writeJsonExclusiveAtomically(path.join(realRoot, `${verificationId}.json`), {
149
+ schemaVersion: "OwlCodaRunKitVerificationPreflightV1",
150
+ runId,
151
+ verificationId,
152
+ status: "rejected",
153
+ issueCode,
154
+ executable,
155
+ commandArgvSha256: sha256(JSON.stringify(commandArgv)),
156
+ authorizationGranted: false,
157
+ });
158
+ }
159
+
160
+ function recordRejectedFinalizeAttempt({
161
+ workspaceRoot,
162
+ runId,
163
+ verificationId,
164
+ outputRoot,
165
+ finalizeRequestPath,
166
+ finalized,
167
+ }) {
168
+ const relativeRequestPath = relativeToWorkspace(workspaceRoot, finalizeRequestPath);
169
+ const artifactPath = path.join(outputRoot, "finalize-result.json");
170
+ writeJsonExclusiveAtomically(artifactPath, {
171
+ schemaVersion: "OwlCodaRunKitVerificationFinalizeAttemptV1",
172
+ runId,
173
+ verificationId,
174
+ status: "rejected",
175
+ gateStatus: finalized.status,
176
+ finalizeRequestPath: relativeRequestPath,
177
+ finalizeRequestSha256: sha256(readFileSync(finalizeRequestPath)),
178
+ result: finalized,
179
+ authorizationGranted: false,
180
+ });
181
+ return relativeToWorkspace(workspaceRoot, artifactPath);
182
+ }
183
+
92
184
  function gitVersion() {
93
185
  return execFileSync("git", ["--version"], { encoding: "utf8" })
94
186
  .trim()
@@ -203,6 +295,20 @@ function runHighLevelVerifyWithinControlTransaction({
203
295
  const { executionRoot, pinGate } = loadActiveExecution(workspaceRoot, runId);
204
296
  if (pinGate.status !== "valid") return { ...pinGate, authorizationGranted: false };
205
297
  regularDirectory(executionRoot, "Execution directory");
298
+ const [executable] = commandArgv;
299
+ const executableGate = verificationExecutableGate(executable);
300
+ if (!executableGate.valid) {
301
+ recordRejectedVerificationPreflight({
302
+ workspaceRoot,
303
+ executionRoot,
304
+ runId,
305
+ verificationId,
306
+ executable,
307
+ commandArgv,
308
+ issueCode: executableGate.issueCode,
309
+ });
310
+ throw new Error(executableGate.message);
311
+ }
206
312
  for (const [name, label, create] of [
207
313
  ["delivery-packets", "Delivery packet directory", false],
208
314
  ["snapshots", "Snapshot directory", true],
@@ -213,9 +319,6 @@ function runHighLevelVerifyWithinControlTransaction({
213
319
  if (create) ensureRegularDirectory(directoryPath, label);
214
320
  else regularDirectory(directoryPath, label);
215
321
  }
216
- const [executable] = commandArgv;
217
- if (!path.isAbsolute(executable)) throw new Error("verify executable after -- must be an absolute path.");
218
- regularFile(executable, "verify executable");
219
322
  const realCwd = realpathSync(cwd === "." ? workspaceRoot : path.join(workspaceRoot, cwd));
220
323
  if (!within(workspaceRoot, realCwd)) throw new Error("verify cwd escapes the workspace through a symlink.");
221
324
  for (const outputPath of [
@@ -269,7 +372,19 @@ function runHighLevelVerifyWithinControlTransaction({
269
372
  };
270
373
  writeJsonExclusiveAtomically(finalizeRequestPath, finalizeRequest);
271
374
  const finalized = runFinalize({ workspaceRoot, runId, request: finalizeRequest });
272
- if (finalized.status !== "accepted_passed") return finalized;
375
+ if (finalized.status !== "accepted_passed") {
376
+ return {
377
+ ...finalized,
378
+ finalizeResultPath: recordRejectedFinalizeAttempt({
379
+ workspaceRoot,
380
+ runId,
381
+ verificationId,
382
+ outputRoot,
383
+ finalizeRequestPath,
384
+ finalized,
385
+ }),
386
+ };
387
+ }
273
388
  return {
274
389
  status: "verified",
275
390
  exitCode: 0,