fix(skills): address develop workflow review
This commit is contained in:
@@ -234,33 +234,18 @@ async function syncDirectory(io, directory) {
|
||||
}
|
||||
}
|
||||
|
||||
function requestFromArgs(targetOrRequest, input, options) {
|
||||
if (typeof targetOrRequest === "string" || targetOrRequest instanceof URL) {
|
||||
return { ...(options ?? {}), target: targetOrRequest, input };
|
||||
}
|
||||
if (targetOrRequest === null || typeof targetOrRequest !== "object") {
|
||||
/** Atomically create or replace a validated workflow record. */
|
||||
export async function checkpointRecord(request) {
|
||||
if (request === null || typeof request !== "object") {
|
||||
throw new CheckpointError("INVALID_REQUEST", "checkpoint request must provide a target and input");
|
||||
}
|
||||
return targetOrRequest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Atomically create or replace a validated workflow record.
|
||||
*
|
||||
* Object form: `checkpointRecord({ target, input, expectedSha256, io })`.
|
||||
* Positional form is also supported by `recordCheckpoint(target, input, options)`.
|
||||
*/
|
||||
export async function checkpointRecord(targetOrRequest, input, options) {
|
||||
const request = requestFromArgs(targetOrRequest, input, options);
|
||||
const targetValue = request.target;
|
||||
if (typeof targetValue !== "string" && !(targetValue instanceof URL)) {
|
||||
if (typeof request.target !== "string" || request.target.length === 0) {
|
||||
throw new CheckpointError("INVALID_REQUEST", "checkpoint target is required");
|
||||
}
|
||||
const target = resolve(targetValue instanceof URL ? fileURLToPath(targetValue) : targetValue);
|
||||
const source = request.input ?? request.content;
|
||||
// This deliberately happens before opening the lock or reading the destination.
|
||||
const { bytes } = validateRecord(source);
|
||||
const expected = expectedDigest(request.expectedSha256 ?? request.expectedDigest);
|
||||
const target = resolve(request.target);
|
||||
// Validate before opening the lock, creating a directory, or reading the destination.
|
||||
const { bytes } = validateRecord(request.input);
|
||||
const expected = expectedDigest(request.expectedSha256);
|
||||
const io = withIo(request.io);
|
||||
const lock = `${target}.lock`;
|
||||
const directory = dirname(target);
|
||||
@@ -398,12 +383,6 @@ export async function checkpointRecord(targetOrRequest, input, options) {
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function recordCheckpoint(target, input, options = {}) {
|
||||
return checkpointRecord(target, input, options);
|
||||
}
|
||||
|
||||
export const writeCheckpoint = recordCheckpoint;
|
||||
|
||||
function usage() {
|
||||
return "Usage: node checkpoint-record.mjs <target> [--input <path>] [--expected-sha256 <digest>]";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user