gencow 0.1.283 → 0.1.285
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/core/index.js +3 -0
- package/lib/app-command.mjs +73 -4
- package/lib/cli-command-runner.mjs +5 -0
- package/lib/db-check-deadline.mjs +45 -0
- package/lib/db-push-command.mjs +58 -21
- package/lib/deploy-admission-boundary.mjs +18 -1
- package/lib/deploy-admission-transport-failure.mjs +148 -0
- package/lib/deploy-command.mjs +8 -2
- package/lib/deploy-failure-diagnostic.mjs +9 -0
- package/lib/deploy-package-runtime.mjs +3 -3
- package/lib/deploy-runtime.mjs +16 -1
- package/lib/deployment-admission-retry.mjs +6 -1
- package/lib/env-command.mjs +50 -4
- package/lib/migration-diagnostic.mjs +27 -7
- package/lib/platform-client.mjs +3 -2
- package/lib/prod-create-auth-diagnostic.mjs +62 -13
- package/lib/static-deploy-command.mjs +3 -0
- package/package.json +3 -3
- package/runtime/server.mjs +116 -112
- package/runtime/tooling.mjs +3 -0
package/lib/env-command.mjs
CHANGED
|
@@ -9,9 +9,12 @@ import {
|
|
|
9
9
|
import { resolveCloudAppTargetWithServerEnvironment } from "./cloud-target-environment.mjs";
|
|
10
10
|
import { cloudTargetRejectionMessage, prodRetryCommandLine, redactConfigSetValue, redactEnvPairs } from "./deploy-app-target.mjs";
|
|
11
11
|
import { BOLD, CYAN, DIM, GREEN, RESET, error, info, log, success, warn } from "./output.mjs";
|
|
12
|
+
import { renderLifecycleFailure } from "./app-lifecycle-format.mjs";
|
|
12
13
|
import { platformFetch, requireCreds, rpcQuery } from "./platform-client.mjs";
|
|
13
14
|
|
|
14
15
|
const ENV_RESPONSE_UNREADABLE_CODE = "ENV_RESPONSE_UNREADABLE";
|
|
16
|
+
const ENV_APP_NOT_FOUND_REASON = "App not found";
|
|
17
|
+
const ENV_APP_NOT_FOUND_CODE = "APP_NOT_FOUND";
|
|
15
18
|
|
|
16
19
|
// Reads a failed platform response. A JSON `null`, an empty body, or a non-object body
|
|
17
20
|
// normalizes to `message: null`, so callers never dereference the parsed value.
|
|
@@ -19,7 +22,24 @@ async function readEnvErrorResponse(response) {
|
|
|
19
22
|
const parsed = await response.json().catch(() => null);
|
|
20
23
|
const body = parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : null;
|
|
21
24
|
const message = typeof body?.error === "string" && body.error.trim() ? body.error.trim() : null;
|
|
22
|
-
|
|
25
|
+
const code = typeof body?.code === "string" ? body.code : null;
|
|
26
|
+
return { ...envResponseFacts(response), message, code };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// The Platform's typed missing-app answer is code APP_NOT_FOUND. Servers that predate the code answer
|
|
30
|
+
// 404 with the text "App not found", so that text is used only when no code is present.
|
|
31
|
+
function isEnvAppNotFound(failure) {
|
|
32
|
+
if (failure.status !== 404) return false;
|
|
33
|
+
if (typeof failure.code === "string") return failure.code === ENV_APP_NOT_FOUND_CODE;
|
|
34
|
+
return failure.message === ENV_APP_NOT_FOUND_REASON;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Shared typed rendering (same catalog as app status); the stage and correlation are the only per-call facts.
|
|
38
|
+
function envAppNotFoundOutput(failure, appId, stage) {
|
|
39
|
+
return renderLifecycleFailure("APP_NOT_FOUND", {
|
|
40
|
+
name: appId,
|
|
41
|
+
extra: [`Stage: ${stage}`, `Correlation: ${failure.correlationId ?? "none returned"}`],
|
|
42
|
+
});
|
|
23
43
|
}
|
|
24
44
|
|
|
25
45
|
function envResponseFacts(response) {
|
|
@@ -331,6 +351,15 @@ export function createEnvCommand(deps = {}) {
|
|
|
331
351
|
// A `null` or non-object error body must not turn into a TypeError that hides the HTTP status.
|
|
332
352
|
const body = await res.json().catch(() => null);
|
|
333
353
|
const reason = typeof body?.error === "string" && body.error ? body.error : null;
|
|
354
|
+
const failure = {
|
|
355
|
+
...envResponseFacts(res),
|
|
356
|
+
message: reason,
|
|
357
|
+
code: typeof body?.code === "string" ? body.code : null,
|
|
358
|
+
};
|
|
359
|
+
if (isEnvAppNotFound(failure)) {
|
|
360
|
+
error(envAppNotFoundOutput(failure, appId, "env_list"));
|
|
361
|
+
return 1;
|
|
362
|
+
}
|
|
334
363
|
throw new Error(reason ?? `HTTP ${res.status}`);
|
|
335
364
|
}
|
|
336
365
|
const vars = await res.json().catch(() => null);
|
|
@@ -421,8 +450,14 @@ export function createEnvCommand(deps = {}) {
|
|
|
421
450
|
body: JSON.stringify({ key: name, value, env: envTarget }),
|
|
422
451
|
});
|
|
423
452
|
if (!res.ok) {
|
|
453
|
+
const failure = await readEnvErrorResponse(res);
|
|
454
|
+
if (isEnvAppNotFound(failure)) {
|
|
455
|
+
error(envAppNotFoundOutput(failure, appId, "env_set"));
|
|
456
|
+
commandFailed = true;
|
|
457
|
+
continue;
|
|
458
|
+
}
|
|
424
459
|
throw new Error(
|
|
425
|
-
formatEnvErrorMessage(
|
|
460
|
+
formatEnvErrorMessage(failure, {
|
|
426
461
|
stage: "env_set",
|
|
427
462
|
checkCommand: envListCommand(appId, envTarget),
|
|
428
463
|
}),
|
|
@@ -476,8 +511,14 @@ export function createEnvCommand(deps = {}) {
|
|
|
476
511
|
},
|
|
477
512
|
);
|
|
478
513
|
if (!res.ok) {
|
|
514
|
+
const failure = await readEnvErrorResponse(res);
|
|
515
|
+
if (isEnvAppNotFound(failure)) {
|
|
516
|
+
error(envAppNotFoundOutput(failure, appId, "env_unset"));
|
|
517
|
+
commandFailed = true;
|
|
518
|
+
continue;
|
|
519
|
+
}
|
|
479
520
|
throw new Error(
|
|
480
|
-
formatEnvErrorMessage(
|
|
521
|
+
formatEnvErrorMessage(failure, {
|
|
481
522
|
stage: "env_unset",
|
|
482
523
|
checkCommand: envListCommand(appId, envTarget),
|
|
483
524
|
}),
|
|
@@ -572,8 +613,13 @@ export function createEnvCommand(deps = {}) {
|
|
|
572
613
|
body: JSON.stringify({ vars, env: envTarget }),
|
|
573
614
|
});
|
|
574
615
|
if (!res.ok) {
|
|
616
|
+
const failure = await readEnvErrorResponse(res);
|
|
617
|
+
if (isEnvAppNotFound(failure)) {
|
|
618
|
+
error(envAppNotFoundOutput(failure, appId, "env_push"));
|
|
619
|
+
return 1;
|
|
620
|
+
}
|
|
575
621
|
throw new Error(
|
|
576
|
-
formatEnvErrorMessage(
|
|
622
|
+
formatEnvErrorMessage(failure, {
|
|
577
623
|
stage: "env_push",
|
|
578
624
|
checkCommand: envListCommand(appId, envTarget),
|
|
579
625
|
}),
|
|
@@ -477,7 +477,12 @@ export function buildMigrationNoResponseDiagnostic(
|
|
|
477
477
|
};
|
|
478
478
|
}
|
|
479
479
|
|
|
480
|
-
|
|
480
|
+
/**
|
|
481
|
+
* `deadline` is set only when the CLI itself stopped waiting after its bounded check deadline
|
|
482
|
+
* (`timeoutMs`). The producer code and the database-state claim are shared with the transport failure.
|
|
483
|
+
*/
|
|
484
|
+
export function buildMigrationCheckNoResponseDiagnostic(correlationId, retryCommand, deadline) {
|
|
485
|
+
const timedOut = Number.isSafeInteger(deadline?.timeoutMs) && deadline.timeoutMs > 0;
|
|
481
486
|
return {
|
|
482
487
|
diagnosticVersion: 1,
|
|
483
488
|
code: "MIGRATION_CHECK_RESPONSE_NOT_RECEIVED",
|
|
@@ -488,12 +493,27 @@ export function buildMigrationCheckNoResponseDiagnostic(correlationId, retryComm
|
|
|
488
493
|
retryPolicy: "IMMEDIATE",
|
|
489
494
|
retryCondition: "The dry-run endpoint never executes tenant DDL, so a fresh check is safe.",
|
|
490
495
|
correlationId: safeClientCorrelationId(correlationId),
|
|
491
|
-
reason:
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
496
|
+
reason: timedOut
|
|
497
|
+
? {
|
|
498
|
+
code: "migration_check_response_not_received",
|
|
499
|
+
summary: `The Gencow Platform did not respond to the migration check within ${deadline.timeoutMs}ms, so the CLI stopped waiting.`,
|
|
500
|
+
detail:
|
|
501
|
+
"db:check is read-only: this command did not promote the uploaded schema bundle and did not change the database or serving state. The server may still be finishing the request; the CLI cannot tell whether it did.",
|
|
502
|
+
}
|
|
503
|
+
: {
|
|
504
|
+
code: "migration_check_response_not_received",
|
|
505
|
+
summary: "The CLI did not receive the final migration check response.",
|
|
506
|
+
detail: "The server-side check path is read-only and does not promote the uploaded schema bundle.",
|
|
507
|
+
},
|
|
508
|
+
suggestedFixes: timedOut
|
|
509
|
+
? [
|
|
510
|
+
{
|
|
511
|
+
title: "Raise the check deadline if the Platform is slow",
|
|
512
|
+
detail:
|
|
513
|
+
"Set GENCOW_DB_CHECK_TIMEOUT_MS to a larger value in milliseconds (100 to 600000, default 60000), then rerun the same command.",
|
|
514
|
+
},
|
|
515
|
+
]
|
|
516
|
+
: [],
|
|
497
517
|
nextAction: { kind: "RETRY", ...(retryCommand ? { command: retryCommand } : {}) },
|
|
498
518
|
forbiddenActions: [
|
|
499
519
|
"Do not use --force to bypass migration safety checks.",
|
package/lib/platform-client.mjs
CHANGED
|
@@ -215,10 +215,11 @@ export async function platformFetchJsonWithDeadline(
|
|
|
215
215
|
}
|
|
216
216
|
}
|
|
217
217
|
|
|
218
|
-
export async function rpcQuery(creds, queryName, args = {}) {
|
|
218
|
+
export async function rpcQuery(creds, queryName, args = {}, requestOptions = {}) {
|
|
219
219
|
return platformFetch(creds, "/api/query", {
|
|
220
|
+
...requestOptions,
|
|
220
221
|
method: "POST",
|
|
221
|
-
headers: { "Content-Type": "application/json" },
|
|
222
|
+
headers: { ...requestOptions.headers, "Content-Type": "application/json" },
|
|
222
223
|
body: JSON.stringify({ name: queryName, args }),
|
|
223
224
|
});
|
|
224
225
|
}
|
|
@@ -51,37 +51,86 @@ export function credentialEnvNameOf(creds) {
|
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
export function formatCreateProdAuthMessage(diagnostic, credentialEnvName = null) {
|
|
54
|
+
return formatCliAuthFailureLines(diagnostic, {
|
|
55
|
+
operation: "Prod app creation",
|
|
56
|
+
changed: "nothing (no prod app was created)",
|
|
57
|
+
credentialEnvName,
|
|
58
|
+
}).join("\n");
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Typed auth rejection for a deploy-family route (deploy, deploy status, static, rollback). Only the
|
|
63
|
+
* allow-listed route codes below are rendered, so a response from an older or unknown route keeps its
|
|
64
|
+
* previous output. The same reader serves every deploy-family command.
|
|
65
|
+
*/
|
|
66
|
+
const ROUTE_CREDENTIAL_CODES = new Set([
|
|
67
|
+
CREDENTIAL_REJECTED_CODE,
|
|
68
|
+
"APP_DEPLOY_AUTH_REQUIRED",
|
|
69
|
+
"APP_DEPLOY_STATUS_AUTH_REQUIRED",
|
|
70
|
+
"APP_STATIC_DEPLOY_AUTH_REQUIRED",
|
|
71
|
+
"APP_ROLLBACK_AUTH_REQUIRED",
|
|
72
|
+
]);
|
|
73
|
+
|
|
74
|
+
export function readTypedCliAuthDiagnostic(body) {
|
|
75
|
+
if (!body || typeof body !== "object" || Array.isArray(body)) return null;
|
|
76
|
+
if (body.stage !== "auth") return null;
|
|
77
|
+
const correlationId =
|
|
78
|
+
typeof body.correlationId === "string" && CORRELATION_ID_PATTERN.test(body.correlationId)
|
|
79
|
+
? body.correlationId
|
|
80
|
+
: null;
|
|
81
|
+
if (body.code === LOOKUP_UNAVAILABLE_CODE && body.nextAction === "RETRY") {
|
|
82
|
+
return { kind: "unavailable", code: LOOKUP_UNAVAILABLE_CODE, correlationId };
|
|
83
|
+
}
|
|
84
|
+
if (ROUTE_CREDENTIAL_CODES.has(body.code)) {
|
|
85
|
+
return {
|
|
86
|
+
kind: "credential",
|
|
87
|
+
code: body.code,
|
|
88
|
+
causeCode: safeAuthCauseCode(body.causeCode),
|
|
89
|
+
correlationId,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
if (ACCOUNT_MESSAGES.has(body.code) && body.nextAction === "CHECK_ACCOUNT") {
|
|
93
|
+
return { kind: "account", code: body.code, correlationId };
|
|
94
|
+
}
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Renders a typed auth diagnostic as lines whose first line starts with `${operation} failed:`.
|
|
100
|
+
* `changed` states what the failed request left untouched; the message text comes from this file only.
|
|
101
|
+
*/
|
|
102
|
+
export function formatCliAuthFailureLines(diagnostic, options = {}) {
|
|
103
|
+
const operation = options.operation ?? "Deploy";
|
|
104
|
+
// `changed` is the full phrase after "Changed:", for example "nothing (no prod app was created)".
|
|
105
|
+
const changed = options.changed ?? "nothing (no app or deployment state was changed)";
|
|
106
|
+
const credentialEnvName = options.credentialEnvName ?? null;
|
|
54
107
|
const correlation = diagnostic.correlationId ?? "none returned";
|
|
55
108
|
if (diagnostic.kind === "unavailable") {
|
|
56
109
|
return [
|
|
57
|
-
|
|
110
|
+
`${operation} failed: Authentication lookup temporarily unavailable`,
|
|
58
111
|
`Code: ${diagnostic.code}`,
|
|
59
112
|
"Stage: auth",
|
|
60
|
-
|
|
113
|
+
`Changed: ${changed}`,
|
|
61
114
|
"Retryable: yes",
|
|
62
115
|
"Next: wait a short while, then run the same command again. If it keeps failing, send the Correlation ID.",
|
|
63
116
|
`Correlation ID: ${correlation}`,
|
|
64
|
-
]
|
|
117
|
+
];
|
|
65
118
|
}
|
|
66
119
|
if (diagnostic.kind === "account") {
|
|
67
120
|
return [
|
|
68
|
-
|
|
121
|
+
`${operation} failed: ${ACCOUNT_MESSAGES.get(diagnostic.code)}`,
|
|
69
122
|
`Code: ${diagnostic.code}`,
|
|
70
123
|
"Stage: auth",
|
|
71
|
-
|
|
124
|
+
`Changed: ${changed}`,
|
|
72
125
|
"Retryable: no",
|
|
73
126
|
`Next: ${ACCOUNT_NEXT_ACTION}`,
|
|
74
127
|
`Correlation ID: ${correlation}`,
|
|
75
|
-
]
|
|
128
|
+
];
|
|
76
129
|
}
|
|
77
|
-
const lines = [
|
|
78
|
-
"Prod app creation failed: CLI authentication is required",
|
|
79
|
-
`Code: ${diagnostic.code}`,
|
|
80
|
-
"Stage: auth",
|
|
81
|
-
];
|
|
130
|
+
const lines = [`${operation} failed: CLI authentication is required`, `Code: ${diagnostic.code}`, "Stage: auth"];
|
|
82
131
|
if (diagnostic.causeCode) lines.push(`Cause: ${diagnostic.causeCode}`);
|
|
83
|
-
lines.push(
|
|
132
|
+
lines.push(`Changed: ${changed}`, "Retryable: no");
|
|
84
133
|
lines.push(`Next: ${authCauseNextAction(credentialEnvName)}`);
|
|
85
134
|
lines.push(`Correlation ID: ${correlation}`);
|
|
86
|
-
return lines
|
|
135
|
+
return lines;
|
|
87
136
|
}
|
|
@@ -22,6 +22,7 @@ import { buildDeployClaimFromArchive } from "./deploy-package-claim.mjs";
|
|
|
22
22
|
import { getCliInvocationSelection } from "./project-context.mjs";
|
|
23
23
|
import { pollAcceptedDeploymentOperation } from "./deployment-operation-poll.mjs";
|
|
24
24
|
import { renderDeployFailureDiagnosticLines } from "./deploy-failure-diagnostic.mjs";
|
|
25
|
+
import { credentialEnvNameOf } from "./prod-create-auth-diagnostic.mjs";
|
|
25
26
|
import { writeProjectMetadata } from "./deploy-project-metadata.mjs";
|
|
26
27
|
import { postDeploymentAdmissionWithTimeout } from "./deploy-admission-boundary.mjs";
|
|
27
28
|
import { installLocalDeployInterruptGuard } from "./local-deploy-interrupt-guard.mjs";
|
|
@@ -598,6 +599,7 @@ export function createStaticDeployRuntime({
|
|
|
598
599
|
postDeploymentAdmissionWithTimeout({
|
|
599
600
|
requestId: deployClaim.claim.requestId,
|
|
600
601
|
appName: appId,
|
|
602
|
+
envTarget: opts.envTarget || "dev",
|
|
601
603
|
// Resume static admission directly; fullstack flow skips the
|
|
602
604
|
// already-completed backend component for this scoped receipt.
|
|
603
605
|
resumeCommand: `gencow deploy --static${opts.envTarget === "prod" ? " --prod" : ""} --app ${appId}${opts.clientName ? ` --client ${opts.clientName}` : ""} --resume ${deployClaim.claim.requestId}`,
|
|
@@ -695,6 +697,7 @@ export function createStaticDeployRuntime({
|
|
|
695
697
|
releaseStaticDeployReceipt(staticReceipt);
|
|
696
698
|
const [headline, ...details] = renderDeployFailureDiagnosticLines(errData, deployRes.statusText, {
|
|
697
699
|
expectedAppName: appId,
|
|
700
|
+
credentialEnvName: credentialEnvNameOf(creds),
|
|
698
701
|
});
|
|
699
702
|
errorImpl(headline.replace(/^Deploy failed:/u, "Static deploy failed:"));
|
|
700
703
|
for (const line of details) infoImpl(line);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gencow",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.285",
|
|
4
4
|
"description": "Gencow — AI Backend Engine",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -42,9 +42,9 @@
|
|
|
42
42
|
"postgres": "^3.4.9",
|
|
43
43
|
"@gencow/client": "0.2.8",
|
|
44
44
|
"@gencow/core": "0.1.47",
|
|
45
|
-
"@gencow/
|
|
45
|
+
"@gencow/shared": "0.0.0",
|
|
46
46
|
"@gencow/server": "0.1.3",
|
|
47
|
-
"@gencow/
|
|
47
|
+
"@gencow/react": "0.2.8"
|
|
48
48
|
},
|
|
49
49
|
"scripts": {
|
|
50
50
|
"build": "node scripts/bundle-core.mjs && node scripts/bundle-shared.mjs && node scripts/bundle-server.mjs",
|