@somewhere-cloud/cli 0.38.151 → 0.38.152
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/CHANGELOG.md +5 -0
- package/README.md +14 -0
- package/dist/lib/bundle.js +156 -9
- package/dist/lib/bundle.js.map +3 -3
- package/dist/types/lib/client.d.ts +1 -0
- package/npm-shrinkwrap.json +2 -2
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.38.152
|
|
4
|
+
|
|
5
|
+
- Run a scheduled job twice in a preview with `somewhere cron run <name> --preview --twice` and see each result and table row-count change.
|
|
6
|
+
- Use a Playwright session from `somewhere test-users prepare` with the data testing helper.
|
|
7
|
+
|
|
3
8
|
## 0.38.151
|
|
4
9
|
|
|
5
10
|
- The generated project guide shows where to declare data access and how to check it with signed-in users.
|
package/README.md
CHANGED
|
@@ -346,6 +346,20 @@ From the linked app folder, `session.data('notes', { operation: 'list' })` sends
|
|
|
346
346
|
the signed-in session, app Origin and deployed contract. For a shell probe, run
|
|
347
347
|
`somewhere test-users prepare alice`, then `somewhere data list notes --as alice`.
|
|
348
348
|
The command prints the HTTP status, outcome and rows or error as JSON.
|
|
349
|
+
|
|
350
|
+
To reuse the prepared user in your own Playwright script, run
|
|
351
|
+
`somewhere test-users prepare alice` in the linked app folder:
|
|
352
|
+
|
|
353
|
+
```ts
|
|
354
|
+
import { data } from '@somewhere-cloud/cli/testing';
|
|
355
|
+
const alice = await browser.newContext({ storageState: '.somewhere/test/alice.state.json' });
|
|
356
|
+
const response = await data(alice.request, 'notes', { operation: 'list' });
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
`data()` uses the linked app's contract and the context's own session. Save the
|
|
360
|
+
context's storage state back to the same file if the app refreshes the session.
|
|
361
|
+
Run `somewhere test-users cleanup` when finished.
|
|
362
|
+
|
|
349
363
|
`expectRefusal(response, 403, 'DATA_ACCESS_DENIED')` checks the exact status and
|
|
350
364
|
code. For an empty scoped read, also check that the owner can read the same fixture.
|
|
351
365
|
|
package/dist/lib/bundle.js
CHANGED
|
@@ -42604,7 +42604,8 @@ var init_client = __esm({
|
|
|
42604
42604
|
method,
|
|
42605
42605
|
headers,
|
|
42606
42606
|
body: reqBody,
|
|
42607
|
-
signal: AbortSignal.timeout(timeoutMs)
|
|
42607
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
42608
|
+
...opts?.redirect ? { redirect: opts.redirect } : {}
|
|
42608
42609
|
}, timeoutMs);
|
|
42609
42610
|
} catch (err) {
|
|
42610
42611
|
const cause = err.cause;
|
|
@@ -78144,7 +78145,7 @@ function formatChecksReport(check) {
|
|
|
78144
78145
|
if (schedules === null)
|
|
78145
78146
|
lines.push("Registered schedules could not be listed.");
|
|
78146
78147
|
if (schedules?.length)
|
|
78147
|
-
lines.push(`${schedules.length} registered ${schedules.length === 1 ? "schedule" : "schedules"} did not run (${schedules.join(", ")}).`);
|
|
78148
|
+
lines.push(`${schedules.length} registered ${schedules.length === 1 ? "schedule" : "schedules"} did not run (${schedules.join(", ")}). Run one on your preview with ${cliInvocation()} cron run <name> --preview --wait.`);
|
|
78148
78149
|
if (other.length)
|
|
78149
78150
|
lines.push(`Other checks skipped or out of scope: ${other.join(", ")}.`);
|
|
78150
78151
|
} else {
|
|
@@ -133037,6 +133038,123 @@ var init_git = __esm({
|
|
|
133037
133038
|
}
|
|
133038
133039
|
});
|
|
133039
133040
|
|
|
133041
|
+
// dist/lib/test-preview-job.js
|
|
133042
|
+
function rowCountChanges(before, after) {
|
|
133043
|
+
if (!before || !after || Object.keys(before).length !== Object.keys(after).length)
|
|
133044
|
+
return void 0;
|
|
133045
|
+
if (Object.keys(before).some((table2) => !Object.hasOwn(after, table2)))
|
|
133046
|
+
return void 0;
|
|
133047
|
+
return Object.keys(after).sort().filter((table2) => before[table2] !== after[table2]).map((table2) => ({ table: table2, before: before[table2], after: after[table2] }));
|
|
133048
|
+
}
|
|
133049
|
+
async function runPreviewScheduleTest(client, cronId, target, twice, report2, sleep3 = (ms2) => new Promise((resolve26) => setTimeout(resolve26, ms2))) {
|
|
133050
|
+
const path3 = `/cron/${encodeURIComponent(cronId)}/run-preview`;
|
|
133051
|
+
const validTarget = /* @__PURE__ */ __name((value) => value.preview_session_id === target.preview_session_id && value.preview_id === target.preview_id, "validTarget");
|
|
133052
|
+
const first = await client.call("GET", path3, void 0, { ...target, counts: twice ? 1 : void 0 });
|
|
133053
|
+
if (!validTarget(first) || !first.notice)
|
|
133054
|
+
throw new Error("The platform did not confirm the preview job test target.");
|
|
133055
|
+
report2(first.notice);
|
|
133056
|
+
let before = first.row_counts;
|
|
133057
|
+
let countsReason = first.row_counts_reason;
|
|
133058
|
+
const runs = [];
|
|
133059
|
+
for (let index = 0; index < (twice ? 2 : 1); index++) {
|
|
133060
|
+
let requestId;
|
|
133061
|
+
let jobId;
|
|
133062
|
+
let timeoutSeconds = 270;
|
|
133063
|
+
try {
|
|
133064
|
+
const response = await client.callRaw("POST", path3, target, { captureIncompleteBody: true, redirect: "error" });
|
|
133065
|
+
requestId = response.headers["x-request-id"] ?? response.headers["cf-ray"];
|
|
133066
|
+
const envelope = JSON.parse(response.body);
|
|
133067
|
+
if (response.status >= 400 && response.status < 500 && typeof envelope.error === "string") {
|
|
133068
|
+
runs.push({ status: "refused", duration_ms: null, request_id: requestId, detail: envelope.message ?? envelope.error });
|
|
133069
|
+
break;
|
|
133070
|
+
}
|
|
133071
|
+
const data2 = envelope.data;
|
|
133072
|
+
if (response.status === 202 && data2 && data2.preview_session_id === target.preview_session_id && data2.preview_id === target.preview_id && typeof data2.job_id === "string" && data2.job_id.startsWith("job_")) {
|
|
133073
|
+
jobId = data2.job_id;
|
|
133074
|
+
if (typeof data2.timeout_seconds === "number" && data2.timeout_seconds > 0)
|
|
133075
|
+
timeoutSeconds = Math.min(data2.timeout_seconds, timeoutSeconds);
|
|
133076
|
+
}
|
|
133077
|
+
} catch (error3) {
|
|
133078
|
+
if (error3 instanceof CliApiError)
|
|
133079
|
+
requestId = error3.meta.requestId ?? requestId;
|
|
133080
|
+
}
|
|
133081
|
+
if (!jobId) {
|
|
133082
|
+
runs.push({ status: "unknown", duration_ms: null, request_id: requestId, detail: "Job admission is unknown. The request was not resubmitted." });
|
|
133083
|
+
break;
|
|
133084
|
+
}
|
|
133085
|
+
report2(`Queued job ${jobId}${requestId ? ` (request ${requestId})` : ""}.`);
|
|
133086
|
+
const deadline = Date.now() + timeoutSeconds * 1e3;
|
|
133087
|
+
let last;
|
|
133088
|
+
let readFailed = false;
|
|
133089
|
+
while (Date.now() < deadline) {
|
|
133090
|
+
try {
|
|
133091
|
+
const result = await client.call("GET", path3, void 0, { ...target, job_id: jobId, counts: twice ? 1 : void 0 }, { timeoutMs: Math.max(1, deadline - Date.now()), refresh: false });
|
|
133092
|
+
if (!validTarget(result) || result.job?.job_id !== jobId)
|
|
133093
|
+
throw new Error("Unexpected job status receipt");
|
|
133094
|
+
last = result;
|
|
133095
|
+
if (result.job.terminal)
|
|
133096
|
+
break;
|
|
133097
|
+
} catch {
|
|
133098
|
+
readFailed = true;
|
|
133099
|
+
break;
|
|
133100
|
+
}
|
|
133101
|
+
if (Date.now() < deadline)
|
|
133102
|
+
await sleep3(Math.min(1e3, deadline - Date.now()));
|
|
133103
|
+
}
|
|
133104
|
+
const job = last?.job;
|
|
133105
|
+
if (!job?.terminal || job.status === "indeterminate") {
|
|
133106
|
+
const detail = readFailed ? "The job status could not be read." : job?.terminal ? "The job\u2019s execution outcome is indeterminate." : "The job did not reach a terminal status before the wait expired.";
|
|
133107
|
+
runs.push({ status: "unknown", duration_ms: job?.duration_ms ?? null, job_id: jobId, request_id: requestId, detail });
|
|
133108
|
+
break;
|
|
133109
|
+
}
|
|
133110
|
+
const changes = twice ? rowCountChanges(before, last?.row_counts) : void 0;
|
|
133111
|
+
runs.push({
|
|
133112
|
+
status: job.status,
|
|
133113
|
+
duration_ms: job.duration_ms,
|
|
133114
|
+
job_id: jobId,
|
|
133115
|
+
request_id: requestId,
|
|
133116
|
+
...job.error_code ? { detail: job.error_code } : {},
|
|
133117
|
+
...twice ? changes ? { row_count_changes: changes } : { row_counts_reason: last?.row_counts_reason ?? countsReason ?? "Two comparable row count snapshots were unavailable." } : {}
|
|
133118
|
+
});
|
|
133119
|
+
before = last?.row_counts;
|
|
133120
|
+
countsReason = last?.row_counts_reason;
|
|
133121
|
+
}
|
|
133122
|
+
return runs;
|
|
133123
|
+
}
|
|
133124
|
+
async function printPreviewScheduleTest(cronId, preview, twice, json) {
|
|
133125
|
+
const { preview_session_id, preview_id } = await previewCurrentVersion(preview.credential);
|
|
133126
|
+
const version2 = { preview_session_id, preview_id };
|
|
133127
|
+
if (preview.previewSessionId !== version2.preview_session_id)
|
|
133128
|
+
throw new Error("The preview credential did not resolve to this folder\u2019s preview.");
|
|
133129
|
+
const runs = await runPreviewScheduleTest(new ApiClient(getToken()), cronId, version2, twice, (message3) => process.stderr.write(message3 + "\n"));
|
|
133130
|
+
if (json)
|
|
133131
|
+
process.stdout.write(JSON.stringify({ cron_id: cronId, ...version2, runs }) + "\n");
|
|
133132
|
+
else
|
|
133133
|
+
runs.forEach((run, i) => {
|
|
133134
|
+
const receipt = [run.job_id && `job ${run.job_id}`, run.request_id && `request ${run.request_id}`].filter(Boolean).join(", ");
|
|
133135
|
+
const duration3 = run.duration_ms !== null ? ` in ${(run.duration_ms / 1e3).toFixed(2)} s` : "";
|
|
133136
|
+
console.log(`Run ${i + 1} ${run.status}${duration3}${receipt ? ` (${receipt})` : ""}.${run.detail ? ` ${run.detail}` : ""}`);
|
|
133137
|
+
if (run.row_count_changes) {
|
|
133138
|
+
const changes = run.row_count_changes.map(({ table: table2, before, after }) => `${table2} ${before} \u2192 ${after}`);
|
|
133139
|
+
console.log(changes.length ? `Observed row counts changed in ${changes.join(", ")}.` : "No declared table row count changed between reads.");
|
|
133140
|
+
}
|
|
133141
|
+
if (run.row_counts_reason)
|
|
133142
|
+
console.log(`Row count observation unavailable. ${run.row_counts_reason}`);
|
|
133143
|
+
});
|
|
133144
|
+
process.exitCode = runs.some((run) => ["failed", "cancelled"].includes(run.status)) ? 1 : runs.every((run) => run.status === "complete") ? 0 : 2;
|
|
133145
|
+
}
|
|
133146
|
+
var init_test_preview_job = __esm({
|
|
133147
|
+
"dist/lib/test-preview-job.js"() {
|
|
133148
|
+
"use strict";
|
|
133149
|
+
init_client();
|
|
133150
|
+
init_config();
|
|
133151
|
+
init_preview_jobs();
|
|
133152
|
+
__name(rowCountChanges, "rowCountChanges");
|
|
133153
|
+
__name(runPreviewScheduleTest, "runPreviewScheduleTest");
|
|
133154
|
+
__name(printPreviewScheduleTest, "printPreviewScheduleTest");
|
|
133155
|
+
}
|
|
133156
|
+
});
|
|
133157
|
+
|
|
133040
133158
|
// dist/commands/cron.js
|
|
133041
133159
|
function parsePayload(value) {
|
|
133042
133160
|
if (value === void 0)
|
|
@@ -133458,15 +133576,22 @@ zone each trigger is stored in, and \`cron update --schedule\` keeps that zone u
|
|
|
133458
133576
|
console.log(dim(policy));
|
|
133459
133577
|
});
|
|
133460
133578
|
});
|
|
133461
|
-
cron.command("run <cron-id-or-name>").description("Queue one run of a scheduled task now without changing its schedule; --wait waits for it to finish").option("-p, --project <project>", "Project slug or ID used to resolve a task name; defaults to the linked project").option("--wait", "Wait for the queued job to finish and print its result; exits non-zero on failure or timeout").option("--preview", "Run the task's handler and payload once in this folder's open preview instead (its code, data, files and mail); the production schedule never changes").option("--timeout <seconds>", `With --wait, how long to wait before giving up (default ${DEFAULT_WAIT_TIMEOUT_SECONDS})`).option("--json", "Print the complete response as JSON").addHelpText("after", "\nWithout --wait the command returns as soon as the job is queued; the task has not run yet,\nso anything it writes may not be visible for a few seconds. Pass --wait before reading its effects.\n").action(async (target, opts) => {
|
|
133579
|
+
cron.command("run <cron-id-or-name>").description("Queue one run of a scheduled task now without changing its schedule; --wait waits for it to finish").option("-p, --project <project>", "Project slug or ID used to resolve a task name; defaults to the linked project").option("--wait", "Wait for the queued job to finish and print its result; exits non-zero on failure or timeout").option("--preview", "Run the task's handler and payload once in this folder's open preview instead (its code, data, files and mail); the production schedule never changes").option("--twice", "With --preview, wait for each of two runs and report declared table row count changes").option("--timeout <seconds>", `With --wait, how long to wait before giving up (default ${DEFAULT_WAIT_TIMEOUT_SECONDS})`).option("--json", "Print the complete response as JSON").addHelpText("after", "\nWithout --wait the command returns as soon as the job is queued; the task has not run yet,\nso anything it writes may not be visible for a few seconds. Pass --wait before reading its effects.\n").action(async (target, opts) => {
|
|
133462
133580
|
let queued = false;
|
|
133463
133581
|
try {
|
|
133582
|
+
if (opts.twice && (!opts.preview || opts.timeout !== void 0)) {
|
|
133583
|
+
throw new Error("USAGE_ERROR: --twice requires --preview and uses the platform job timeout.");
|
|
133584
|
+
}
|
|
133464
133585
|
const timeoutSeconds = parseWaitTimeout(opts.timeout);
|
|
133465
133586
|
if (opts.timeout !== void 0 && !opts.wait) {
|
|
133466
133587
|
throw new Error("USAGE_ERROR: --timeout only applies with --wait.");
|
|
133467
133588
|
}
|
|
133468
133589
|
const cronId = await resolveCronId(target, opts.project);
|
|
133469
133590
|
if (opts.preview) {
|
|
133591
|
+
if (opts.twice) {
|
|
133592
|
+
await printPreviewScheduleTest(cronId, await folderPreviewTool({}), true, Boolean(opts.json));
|
|
133593
|
+
return;
|
|
133594
|
+
}
|
|
133470
133595
|
await runCronInPreview(cronId, opts, timeoutSeconds);
|
|
133471
133596
|
return;
|
|
133472
133597
|
}
|
|
@@ -133622,6 +133747,7 @@ var DEFAULT_WAIT_TIMEOUT_SECONDS, WAIT_POLL_INTERVAL_MS, JOB_SUCCESS_STATUS, JOB
|
|
|
133622
133747
|
var init_cron = __esm({
|
|
133623
133748
|
"dist/commands/cron.js"() {
|
|
133624
133749
|
"use strict";
|
|
133750
|
+
init_test_preview_job();
|
|
133625
133751
|
init_cli_invocation();
|
|
133626
133752
|
init_config();
|
|
133627
133753
|
init_next_actions();
|
|
@@ -135171,7 +135297,8 @@ function registerTestUsers(program2) {
|
|
|
135171
135297
|
group.command("prepare <actors...>").description("Create preverified test users and write one Playwright storageState file per actor (e.g. alice bob:admin)").option("-p, --project <project>", "Project slug or ID; defaults to the linked project").option("--origin <url>", "Only the project's production origin is supported; anything else is refused").option("--json", "Print the manifest (no tokens) as JSON").addHelpText("after", [
|
|
135172
135298
|
"",
|
|
135173
135299
|
"From the linked project folder, run somewhere test-users prepare alice. It writes .somewhere/test/<actor>.state.json (a standard Playwright storageState) and manifest.json.",
|
|
135174
|
-
'Playwright: browser.newContext({ storageState: ".somewhere/test/alice.state.json" })',
|
|
135300
|
+
'Playwright: const alice = await browser.newContext({ storageState: ".somewhere/test/alice.state.json" })',
|
|
135301
|
+
'With data imported from @somewhere-cloud/cli/testing: await data(alice.request, "notes", { operation: "list" })',
|
|
135175
135302
|
'Save the context back after each run: await context.storageState({ path: ".somewhere/test/alice.state.json" })',
|
|
135176
135303
|
"The app refreshes the short-lived access token and rotates the session on its first refresh, so an unsaved",
|
|
135177
135304
|
"file stops working after a run that refreshed it. The prepared session starts with the expiry prepare",
|
|
@@ -136825,12 +136952,31 @@ async function refusedAs(person, target, request2, options2) {
|
|
|
136825
136952
|
throw new Error(`expectRefused: ${said}, but ${target} ${String(id)} ${after === null ? "is gone" : "changed"} for the allowed person afterwards.`);
|
|
136826
136953
|
}
|
|
136827
136954
|
}
|
|
136828
|
-
function data(client, table2, request2) {
|
|
136829
|
-
if (
|
|
136830
|
-
|
|
136831
|
-
|
|
136955
|
+
async function data(client, table2, request2) {
|
|
136956
|
+
if (digests.has(client)) {
|
|
136957
|
+
return client.post("/__sw/data", { data: { ...request2, table: table2, contract: digests.get(client) ?? "" } });
|
|
136958
|
+
}
|
|
136959
|
+
const projectId = loadProjectConfig()?.project_id;
|
|
136960
|
+
if (!projectId)
|
|
136961
|
+
throw new Error("Use the data helper from a linked project folder.");
|
|
136962
|
+
let target = contextTargets.get(client);
|
|
136963
|
+
if (!target || target.projectId !== projectId) {
|
|
136964
|
+
const load2 = fixtureTestTarget(new ApiClient(process.env.SW_TEST_TARGET ? null : getToken()), projectId).catch((error3) => {
|
|
136965
|
+
if (contextTargets.get(client)?.load === load2)
|
|
136966
|
+
contextTargets.delete(client);
|
|
136967
|
+
throw error3;
|
|
136968
|
+
});
|
|
136969
|
+
target = { projectId, load: load2 };
|
|
136970
|
+
contextTargets.set(client, target);
|
|
136971
|
+
}
|
|
136972
|
+
const { origin, contractDigest } = await target.load;
|
|
136973
|
+
return client.post(new URL("/__sw/data", origin).href, {
|
|
136974
|
+
headers: { Origin: origin },
|
|
136975
|
+
maxRedirects: 0,
|
|
136976
|
+
data: { ...request2, table: table2, contract: contractDigest ?? "" }
|
|
136977
|
+
});
|
|
136832
136978
|
}
|
|
136833
|
-
var loaded, digests, eager, test, expect, ENDPOINT, INCONCLUSIVE, constrained, FormRun;
|
|
136979
|
+
var loaded, digests, eager, test, expect, ENDPOINT, INCONCLUSIVE, contextTargets, constrained, FormRun;
|
|
136834
136980
|
var init_playwright_fixtures = __esm({
|
|
136835
136981
|
"dist/lib/playwright-fixtures.js"() {
|
|
136836
136982
|
"use strict";
|
|
@@ -136883,6 +137029,7 @@ var init_playwright_fixtures = __esm({
|
|
|
136883
137029
|
INCONCLUSIVE = "looks the same as an empty table, a missing row or a missing route, so it proves nothing on its own. Pass { allowed: <someone the same request succeeds for> } as the positive control.";
|
|
136884
137030
|
__name(seen, "seen");
|
|
136885
137031
|
__name(refusedAs, "refusedAs");
|
|
137032
|
+
contextTargets = /* @__PURE__ */ new WeakMap();
|
|
136886
137033
|
__name(data, "data");
|
|
136887
137034
|
constrained = /* @__PURE__ */ new WeakSet();
|
|
136888
137035
|
FormRun = class {
|