@solidactions/cli 3.9.0 → 3.10.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/dist/command-manifest.json +1 -1
- package/dist/commands/database.js +18 -21
- package/dist/commands/deploy.js +3 -1
- package/dist/commands/run-list.js +47 -4
- package/dist/utils/database-data-plane.js +39 -0
- package/dist/utils/database-sql-import-runner.js +16 -11
- package/dist/utils/source-provenance.js +53 -4
- package/package.json +1 -1
|
@@ -101,6 +101,7 @@ function resolveDependencies(dependencies) {
|
|
|
101
101
|
filesystem: dependencies.filesystem ?? fs_1.default.promises,
|
|
102
102
|
input: dependencies.input,
|
|
103
103
|
now: dependencies.now ?? Date.now,
|
|
104
|
+
monotonicNow: dependencies.monotonicNow ?? (() => performance.now()),
|
|
104
105
|
abortSignal: dependencies.abortSignal,
|
|
105
106
|
controlPlaneTimeoutMs: dependencies.controlPlaneTimeoutMs,
|
|
106
107
|
dataPlaneTimeoutMs: dependencies.dataPlaneTimeoutMs ?? database_data_plane_1.DEFAULT_DATABASE_DATA_PLANE_TIMEOUT_MS,
|
|
@@ -568,20 +569,18 @@ async function nextWritableInput(iterator, signal) {
|
|
|
568
569
|
});
|
|
569
570
|
});
|
|
570
571
|
}
|
|
571
|
-
function validateWritableAccess(access, now) {
|
|
572
|
+
function validateWritableAccess(access, now, monotonicNow) {
|
|
572
573
|
const value = access;
|
|
573
574
|
const url = typeof value?.url === 'string' ? value.url.trim() : '';
|
|
574
575
|
const token = typeof value?.token === 'string' ? value.token.trim() : '';
|
|
575
|
-
const
|
|
576
|
+
const deadline = (0, database_data_plane_1.databaseCredentialDeadline)(value, now, monotonicNow, WRITABLE_RENEWAL_WINDOW_MS);
|
|
576
577
|
if (value?.mode !== 'write'
|
|
577
578
|
|| url === ''
|
|
578
579
|
|| token === ''
|
|
579
|
-
|| !
|
|
580
|
-
|| !Number.isFinite(expiresAt)
|
|
581
|
-
|| expiresAt <= now + WRITABLE_RENEWAL_WINDOW_MS) {
|
|
580
|
+
|| !deadline) {
|
|
582
581
|
throw new database_data_plane_1.DatabaseOperationError('upstream_unavailable', 'The database access response was invalid.');
|
|
583
582
|
}
|
|
584
|
-
return { url, token,
|
|
583
|
+
return { url, token, deadline };
|
|
585
584
|
}
|
|
586
585
|
class WritableRenewalAttemptError extends Error {
|
|
587
586
|
publicError;
|
|
@@ -593,16 +592,8 @@ class WritableRenewalAttemptError extends Error {
|
|
|
593
592
|
delete this.stack;
|
|
594
593
|
}
|
|
595
594
|
}
|
|
596
|
-
function isAuthenticationExpired(error) {
|
|
597
|
-
const value = error;
|
|
598
|
-
const code = typeof value?.code === 'string' ? value.code.toUpperCase() : '';
|
|
599
|
-
const message = typeof value?.message === 'string' ? value.message : '';
|
|
600
|
-
if (['AUTH_TOKEN_EXPIRED', 'AUTH_EXPIRED', 'TOKEN_EXPIRED'].includes(code))
|
|
601
|
-
return true;
|
|
602
|
-
return code === 'SQLITE_AUTH' && /expired|expiration|\bjwt\b/i.test(message);
|
|
603
|
-
}
|
|
604
595
|
function classifyPullFailure(error) {
|
|
605
|
-
if (
|
|
596
|
+
if ((0, database_data_plane_1.isDatabaseCredentialAuthFailure)(error))
|
|
606
597
|
return 'credential_expiry';
|
|
607
598
|
const value = error;
|
|
608
599
|
const code = typeof value?.code === 'string' ? value.code.toUpperCase() : '';
|
|
@@ -718,6 +709,7 @@ async function databaseCreateWithConfig(name, options, config, dependencies = {}
|
|
|
718
709
|
filesystem: io.filesystem,
|
|
719
710
|
stdout: options.json ? () => undefined : io.stdout,
|
|
720
711
|
now: io.now,
|
|
712
|
+
monotonicNow: io.monotonicNow,
|
|
721
713
|
post: io.post,
|
|
722
714
|
loadClient: io.loadClient,
|
|
723
715
|
controlPlaneTimeoutMs: io.controlPlaneTimeoutMs,
|
|
@@ -757,6 +749,7 @@ async function databaseImportWithConfig(name, file, options, config, dependencie
|
|
|
757
749
|
filesystem: io.filesystem,
|
|
758
750
|
stdout: io.stdout,
|
|
759
751
|
now: io.now,
|
|
752
|
+
monotonicNow: io.monotonicNow,
|
|
760
753
|
post: io.post,
|
|
761
754
|
loadClient: io.loadClient,
|
|
762
755
|
controlPlaneTimeoutMs: io.controlPlaneTimeoutMs,
|
|
@@ -888,7 +881,7 @@ async function databaseWritablePullWithConfig(name, destination, options, config
|
|
|
888
881
|
let ownsSidecars = false;
|
|
889
882
|
let client;
|
|
890
883
|
let localCreateClient;
|
|
891
|
-
let
|
|
884
|
+
let credentialDeadline;
|
|
892
885
|
let inputSession;
|
|
893
886
|
let attachedClosePromise;
|
|
894
887
|
const closeAttachedClient = async () => {
|
|
@@ -925,7 +918,7 @@ async function databaseWritablePullWithConfig(name, destination, options, config
|
|
|
925
918
|
}
|
|
926
919
|
throw safeError;
|
|
927
920
|
}
|
|
928
|
-
const access = validateWritableAccess(loaded.access, io.now());
|
|
921
|
+
const access = validateWritableAccess(loaded.access, io.now(), io.monotonicNow());
|
|
929
922
|
const createClient = loaded.createClient;
|
|
930
923
|
if (initial) {
|
|
931
924
|
await handoffReplicaReservation(io, temp, reservationHandle);
|
|
@@ -987,7 +980,7 @@ async function databaseWritablePullWithConfig(name, destination, options, config
|
|
|
987
980
|
attachedClosePromise = undefined;
|
|
988
981
|
client = opened;
|
|
989
982
|
localCreateClient = createClient;
|
|
990
|
-
|
|
983
|
+
credentialDeadline = access.deadline;
|
|
991
984
|
};
|
|
992
985
|
try {
|
|
993
986
|
if (!await confirmFileOverwrite(target, options, io))
|
|
@@ -1010,7 +1003,10 @@ async function databaseWritablePullWithConfig(name, destination, options, config
|
|
|
1010
1003
|
while (true) {
|
|
1011
1004
|
if (io.abortSignal?.aborted || inputSession.interrupted())
|
|
1012
1005
|
break;
|
|
1013
|
-
|
|
1006
|
+
const deadlineNow = credentialDeadline?.clock === 'monotonic'
|
|
1007
|
+
? io.monotonicNow()
|
|
1008
|
+
: io.now();
|
|
1009
|
+
if (!credentialDeadline || deadlineNow >= credentialDeadline.renewalAt) {
|
|
1014
1010
|
try {
|
|
1015
1011
|
await closeAttachedClient();
|
|
1016
1012
|
await openAttachedClient(false);
|
|
@@ -1064,11 +1060,12 @@ async function databaseWritablePullWithConfig(name, destination, options, config
|
|
|
1064
1060
|
sessionFailure = error;
|
|
1065
1061
|
break;
|
|
1066
1062
|
}
|
|
1067
|
-
if (!
|
|
1063
|
+
if (!(0, database_data_plane_1.isDatabaseCredentialAuthFailure)(error)) {
|
|
1068
1064
|
io.stderr('Database statement failed.');
|
|
1069
1065
|
continue;
|
|
1070
1066
|
}
|
|
1071
|
-
|
|
1067
|
+
const credentialCode = (0, database_data_plane_1.databaseCredentialFailureCode)(credentialDeadline, io.now(), io.monotonicNow());
|
|
1068
|
+
io.stderr(`Database statement has an unknown outcome because of ${credentialCode}.`);
|
|
1072
1069
|
try {
|
|
1073
1070
|
await closeAttachedClient();
|
|
1074
1071
|
await openAttachedClient(false);
|
package/dist/commands/deploy.js
CHANGED
|
@@ -506,7 +506,9 @@ async function deploy(projectName, sourcePath, options = {}) {
|
|
|
506
506
|
}
|
|
507
507
|
// Provenance is optional, best effort, and collected before archiving so
|
|
508
508
|
// the deploy artifact itself can never make the source look dirty.
|
|
509
|
-
const sourceMetadata = safeCollectSourceMetadata(sourceDir, options)
|
|
509
|
+
const sourceMetadata = safeCollectSourceMetadata(sourceDir, options, (directory) => (0, source_provenance_1.collectSourceMetadata)(directory, process.env, (hint) => {
|
|
510
|
+
console.log(chalk_1.default.yellow(`Git provenance hint: ${hint}`));
|
|
511
|
+
}));
|
|
510
512
|
if (sourceMetadata) {
|
|
511
513
|
console.log(chalk_1.default.gray(`Revision to upload (client-reported): ${(0, source_provenance_1.formatRevisionSummary)(sourceMetadata)}`));
|
|
512
514
|
}
|
|
@@ -7,10 +7,15 @@ exports.buildRunListParams = buildRunListParams;
|
|
|
7
7
|
exports.runs = runs;
|
|
8
8
|
exports.summaryStatusLabel = summaryStatusLabel;
|
|
9
9
|
exports.detailedOutcomeTag = detailedOutcomeTag;
|
|
10
|
+
exports.formatRevisionCell = formatRevisionCell;
|
|
11
|
+
exports.formatDetailedRevision = formatDetailedRevision;
|
|
12
|
+
exports.displaySummaryTable = displaySummaryTable;
|
|
13
|
+
exports.displayDetailedList = displayDetailedList;
|
|
10
14
|
const axios_1 = __importDefault(require("axios"));
|
|
11
15
|
const chalk_1 = __importDefault(require("chalk"));
|
|
12
16
|
const api_1 = require("../utils/api");
|
|
13
17
|
const table_1 = require("../utils/table");
|
|
18
|
+
const source_provenance_1 = require("../utils/source-provenance");
|
|
14
19
|
/**
|
|
15
20
|
* Build the params object for GET /api/v1/runs.
|
|
16
21
|
* Extracted as a pure function so it can be unit-tested without mocking axios.
|
|
@@ -121,11 +126,43 @@ function detailedOutcomeTag(run) {
|
|
|
121
126
|
return ' [DEGRADED]';
|
|
122
127
|
return '';
|
|
123
128
|
}
|
|
129
|
+
function revisionSha(revision) {
|
|
130
|
+
if (!revision)
|
|
131
|
+
return null;
|
|
132
|
+
return (0, source_provenance_1.sanitizeDisplayText)(revision.short_sha, 16)
|
|
133
|
+
?? (0, source_provenance_1.sanitizeDisplayText)(revision.commit_sha, 64);
|
|
134
|
+
}
|
|
135
|
+
function formatRevisionCell(revision) {
|
|
136
|
+
const sha = revisionSha(revision);
|
|
137
|
+
if (!sha)
|
|
138
|
+
return '-';
|
|
139
|
+
const dirty = revision?.dirty === true ? '*' : revision?.dirty === false ? '' : '?';
|
|
140
|
+
const behind = typeof revision?.commits_behind === 'number'
|
|
141
|
+
&& Number.isSafeInteger(revision.commits_behind)
|
|
142
|
+
&& revision.commits_behind > 0
|
|
143
|
+
? ` ↓${revision.commits_behind}`
|
|
144
|
+
: '';
|
|
145
|
+
return (0, table_1.sanitizeCell)(`${sha}${dirty}${behind}`);
|
|
146
|
+
}
|
|
147
|
+
function formatDetailedRevision(revision) {
|
|
148
|
+
const sha = revisionSha(revision);
|
|
149
|
+
if (!sha)
|
|
150
|
+
return 'unknown';
|
|
151
|
+
const states = [revision?.dirty === true
|
|
152
|
+
? 'DIRTY'
|
|
153
|
+
: revision?.dirty === false ? 'clean' : 'dirty state unknown'];
|
|
154
|
+
const branch = (0, source_provenance_1.sanitizeDisplayText)(revision?.default_branch, 255);
|
|
155
|
+
if (branch && typeof revision?.commits_behind === 'number'
|
|
156
|
+
&& Number.isSafeInteger(revision.commits_behind) && revision.commits_behind > 0) {
|
|
157
|
+
states.push(`${revision.commits_behind} behind origin/${branch} at deploy`);
|
|
158
|
+
}
|
|
159
|
+
return (0, table_1.sanitizeCell)(`${sha} (${states.join(', ')})`);
|
|
160
|
+
}
|
|
124
161
|
function displaySummaryTable(runsList, projectName) {
|
|
125
162
|
const header = projectName ? `Recent runs for "${projectName}":` : 'Recent runs:';
|
|
126
163
|
console.log(chalk_1.default.blue(header));
|
|
127
164
|
console.log('');
|
|
128
|
-
const headers = ['ID', 'WORKFLOW', 'STATUS', 'TRIGGERED', 'TRIGGERED BY'];
|
|
165
|
+
const headers = ['ID', 'WORKFLOW', 'STATUS', 'REVISION', 'TRIGGERED', 'TRIGGERED BY'];
|
|
129
166
|
const rows = runsList.map((run) => {
|
|
130
167
|
const { label: status } = summaryStatusLabel(run);
|
|
131
168
|
const triggeredAt = run.triggered_at ? new Date(run.triggered_at).toLocaleString() : '-';
|
|
@@ -133,25 +170,28 @@ function displaySummaryTable(runsList, projectName) {
|
|
|
133
170
|
String(run.id || '?'),
|
|
134
171
|
(0, table_1.sanitizeCell)((0, table_1.truncateCell)(run.workflow_name || '?', 24)),
|
|
135
172
|
status,
|
|
173
|
+
formatRevisionCell(run.deployed_revision ?? null),
|
|
136
174
|
triggeredAt,
|
|
137
175
|
(0, table_1.sanitizeCell)(run.triggered_by || '-'),
|
|
138
176
|
];
|
|
139
177
|
});
|
|
140
|
-
const widths = (0, table_1.computeColumnWidths)(headers, rows, { minWidths: [8, 25, 12, 22, 0] });
|
|
178
|
+
const widths = (0, table_1.computeColumnWidths)(headers, rows, { minWidths: [8, 25, 12, 14, 22, 0] });
|
|
141
179
|
console.log(chalk_1.default.gray(headers.map((h, i) => h.padEnd(widths[i])).join('')));
|
|
142
180
|
console.log(chalk_1.default.gray('-'.repeat(widths.reduce((a, b) => a + b, 0))));
|
|
143
181
|
for (let i = 0; i < runsList.length; i++) {
|
|
144
182
|
const run = runsList[i];
|
|
145
|
-
const [id, workflow, status, triggeredAt, triggeredBy] = rows[i];
|
|
183
|
+
const [id, workflow, status, revision, triggeredAt, triggeredBy] = rows[i];
|
|
146
184
|
const { attention } = summaryStatusLabel(run);
|
|
147
185
|
const statusColor = attention ? chalk_1.default.yellow : getStatusColor(status);
|
|
148
186
|
console.log(chalk_1.default.gray(id.padEnd(widths[0])) +
|
|
149
187
|
workflow.padEnd(widths[1]) +
|
|
150
188
|
statusColor(status.padEnd(widths[2])) +
|
|
151
|
-
chalk_1.default.gray(
|
|
189
|
+
chalk_1.default.gray(revision.padEnd(widths[3])) +
|
|
190
|
+
chalk_1.default.gray(triggeredAt.padEnd(widths[4])) +
|
|
152
191
|
chalk_1.default.gray(triggeredBy));
|
|
153
192
|
}
|
|
154
193
|
console.log('');
|
|
194
|
+
console.log(chalk_1.default.gray('REVISION shows latest session: * dirty, ? dirty state unknown, ↓N behind default branch at deploy.'));
|
|
155
195
|
console.log(chalk_1.default.gray(`Showing ${runsList.length} run(s)`));
|
|
156
196
|
}
|
|
157
197
|
function displayDetailedList(runsList, projectName) {
|
|
@@ -167,6 +207,9 @@ function displayDetailedList(runsList, projectName) {
|
|
|
167
207
|
console.log(chalk_1.default.bold(` Run #${run.id}`) + chalk_1.default.gray(` — ${run.workflow_name || '?'} (${run.project_name || '?'})`) + silentTag);
|
|
168
208
|
console.log(` Status: ${statusColor(status)}${chalk_1.default.gray(exitStr)}`);
|
|
169
209
|
console.log(` Trigger: ${chalk_1.default.gray(run.triggered_by || '-')}`);
|
|
210
|
+
if (Object.prototype.hasOwnProperty.call(run, 'deployed_revision')) {
|
|
211
|
+
console.log(` Revision (latest session): ${chalk_1.default.gray(formatDetailedRevision(run.deployed_revision))}`);
|
|
212
|
+
}
|
|
170
213
|
// Timeline
|
|
171
214
|
if (run.timeline) {
|
|
172
215
|
const formatTs = (iso) => iso ? new Date(iso).toLocaleString() : '-';
|
|
@@ -4,6 +4,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.DatabaseOperationError = exports.DEFAULT_DATABASE_DATA_PLANE_TIMEOUT_MS = exports.DEFAULT_DATABASE_CONTROL_PLANE_TIMEOUT_MS = void 0;
|
|
7
|
+
exports.databaseCredentialDeadline = databaseCredentialDeadline;
|
|
8
|
+
exports.isDatabaseCredentialAuthFailure = isDatabaseCredentialAuthFailure;
|
|
9
|
+
exports.databaseCredentialFailureCode = databaseCredentialFailureCode;
|
|
7
10
|
exports.safeDatabaseRequestError = safeDatabaseRequestError;
|
|
8
11
|
exports.runDatabaseClientOperationWithDeadline = runDatabaseClientOperationWithDeadline;
|
|
9
12
|
exports.requestDatabaseOperation = requestDatabaseOperation;
|
|
@@ -15,6 +18,42 @@ exports.formatDatabaseTableValue = formatDatabaseTableValue;
|
|
|
15
18
|
const axios_1 = __importDefault(require("axios"));
|
|
16
19
|
const api_1 = require("./api");
|
|
17
20
|
const database_client_support_1 = require("./database-client-support");
|
|
21
|
+
function databaseCredentialDeadline(access, wallNow, monotonicNow, renewalWindowMs) {
|
|
22
|
+
if (access.expires_in_seconds !== undefined) {
|
|
23
|
+
const lifetime = access.expires_in_seconds;
|
|
24
|
+
if (!Number.isSafeInteger(lifetime)
|
|
25
|
+
|| lifetime <= 0
|
|
26
|
+
|| !Number.isFinite(monotonicNow))
|
|
27
|
+
return null;
|
|
28
|
+
const lifetimeMs = lifetime * 1_000;
|
|
29
|
+
if (lifetimeMs <= renewalWindowMs)
|
|
30
|
+
return null;
|
|
31
|
+
return {
|
|
32
|
+
renewalAt: monotonicNow + lifetimeMs - renewalWindowMs,
|
|
33
|
+
expiresAt: monotonicNow + lifetimeMs,
|
|
34
|
+
clock: 'monotonic',
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
const expiresAt = Date.parse(access.expires_at);
|
|
38
|
+
if (!Number.isFinite(wallNow) || !Number.isFinite(expiresAt) || expiresAt <= wallNow + renewalWindowMs)
|
|
39
|
+
return null;
|
|
40
|
+
return { renewalAt: expiresAt - renewalWindowMs, expiresAt, clock: 'wall' };
|
|
41
|
+
}
|
|
42
|
+
function isDatabaseCredentialAuthFailure(error) {
|
|
43
|
+
const value = error;
|
|
44
|
+
const code = typeof value?.code === 'string' ? value.code.toUpperCase() : '';
|
|
45
|
+
const message = typeof value?.message === 'string' ? value.message : '';
|
|
46
|
+
if (['AUTH_TOKEN_EXPIRED', 'AUTH_EXPIRED', 'TOKEN_EXPIRED'].includes(code))
|
|
47
|
+
return true;
|
|
48
|
+
if (code === 'SQLITE_AUTH' && /expired|expiration|\bjwt\b/i.test(message))
|
|
49
|
+
return true;
|
|
50
|
+
const cause = value?.cause;
|
|
51
|
+
return value?.name === 'LibsqlError' && code === 'SERVER_ERROR' && cause?.status === 401;
|
|
52
|
+
}
|
|
53
|
+
function databaseCredentialFailureCode(deadline, wallNow, monotonicNow) {
|
|
54
|
+
const now = deadline.clock === 'monotonic' ? monotonicNow : wallNow;
|
|
55
|
+
return now >= deadline.expiresAt ? 'database_credential_expired' : 'database_credential_revoked';
|
|
56
|
+
}
|
|
18
57
|
exports.DEFAULT_DATABASE_CONTROL_PLANE_TIMEOUT_MS = 30_000;
|
|
19
58
|
exports.DEFAULT_DATABASE_DATA_PLANE_TIMEOUT_MS = 120_000;
|
|
20
59
|
class DatabaseOperationError extends Error {
|
|
@@ -309,20 +309,18 @@ function batchSql(groups) {
|
|
|
309
309
|
'PRAGMA foreign_keys=ON;',
|
|
310
310
|
].join('\n');
|
|
311
311
|
}
|
|
312
|
-
function validateAccess(access, now) {
|
|
312
|
+
function validateAccess(access, now, monotonicNow) {
|
|
313
313
|
const value = access;
|
|
314
314
|
const url = typeof value?.url === 'string' ? value.url.trim() : '';
|
|
315
315
|
const token = typeof value?.token === 'string' ? value.token.trim() : '';
|
|
316
|
-
const
|
|
316
|
+
const deadline = (0, database_data_plane_1.databaseCredentialDeadline)(value, now, monotonicNow, RENEWAL_WINDOW_MS);
|
|
317
317
|
if (value?.mode !== 'write'
|
|
318
318
|
|| url === ''
|
|
319
319
|
|| token === ''
|
|
320
|
-
|| !
|
|
321
|
-
|| !Number.isFinite(expiresAt)
|
|
322
|
-
|| expiresAt <= now + RENEWAL_WINDOW_MS) {
|
|
320
|
+
|| !deadline) {
|
|
323
321
|
throw importFailure('Database import access was invalid.');
|
|
324
322
|
}
|
|
325
|
-
return { url, token,
|
|
323
|
+
return { url, token, deadline };
|
|
326
324
|
}
|
|
327
325
|
async function acquireClient(prepared, config, dependencies) {
|
|
328
326
|
let loaded;
|
|
@@ -337,7 +335,7 @@ async function acquireClient(prepared, config, dependencies) {
|
|
|
337
335
|
throw error;
|
|
338
336
|
throw importFailure('Database import access could not be renewed.');
|
|
339
337
|
}
|
|
340
|
-
const access = validateAccess(loaded.access, dependencies.now());
|
|
338
|
+
const access = validateAccess(loaded.access, dependencies.now(), dependencies.monotonicNow());
|
|
341
339
|
let client;
|
|
342
340
|
try {
|
|
343
341
|
client = loaded.createClient({
|
|
@@ -358,7 +356,7 @@ async function acquireClient(prepared, config, dependencies) {
|
|
|
358
356
|
}
|
|
359
357
|
throw importFailure('Database import requires atomic multi-statement execution support.');
|
|
360
358
|
}
|
|
361
|
-
return { client,
|
|
359
|
+
return { client, deadline: access.deadline };
|
|
362
360
|
}
|
|
363
361
|
async function closeClient(client, timeoutMs = database_data_plane_1.DEFAULT_DATABASE_DATA_PLANE_TIMEOUT_MS) {
|
|
364
362
|
if (!client)
|
|
@@ -378,7 +376,7 @@ async function runPreparedDatabaseImport(prepared, config, dependencies) {
|
|
|
378
376
|
let suppressResume = false;
|
|
379
377
|
let client;
|
|
380
378
|
let clientClosePromise;
|
|
381
|
-
let
|
|
379
|
+
let deadline;
|
|
382
380
|
let failure;
|
|
383
381
|
const closeCurrentClient = () => {
|
|
384
382
|
clientClosePromise ??= closeClient(client, dependencies.dataPlaneTimeoutMs);
|
|
@@ -386,13 +384,14 @@ async function runPreparedDatabaseImport(prepared, config, dependencies) {
|
|
|
386
384
|
};
|
|
387
385
|
try {
|
|
388
386
|
while (nextStatement < prepared.groups.length) {
|
|
389
|
-
|
|
387
|
+
const deadlineNow = deadline?.clock === 'monotonic' ? dependencies.monotonicNow() : dependencies.now();
|
|
388
|
+
if (!client || !deadline || deadlineNow >= deadline.renewalAt) {
|
|
390
389
|
await closeCurrentClient();
|
|
391
390
|
client = undefined;
|
|
392
391
|
clientClosePromise = undefined;
|
|
393
392
|
const acquired = await acquireClient(prepared, config, dependencies);
|
|
394
393
|
client = acquired.client;
|
|
395
|
-
|
|
394
|
+
deadline = acquired.deadline;
|
|
396
395
|
}
|
|
397
396
|
const batch = nextBatch(prepared.groups, nextStatement);
|
|
398
397
|
try {
|
|
@@ -401,6 +400,11 @@ async function runPreparedDatabaseImport(prepared, config, dependencies) {
|
|
|
401
400
|
catch (error) {
|
|
402
401
|
if (error instanceof database_data_plane_1.DatabaseOperationError)
|
|
403
402
|
throw error;
|
|
403
|
+
if (deadline && (0, database_data_plane_1.isDatabaseCredentialAuthFailure)(error)) {
|
|
404
|
+
const code = (0, database_data_plane_1.databaseCredentialFailureCode)(deadline, dependencies.now(), dependencies.monotonicNow());
|
|
405
|
+
const label = code === 'database_credential_expired' ? 'expired' : 'was revoked';
|
|
406
|
+
throw new database_data_plane_1.DatabaseOperationError(code, `Database credential ${label} during an import batch; the batch outcome is unknown.`);
|
|
407
|
+
}
|
|
404
408
|
throw importFailure('A database import batch failed.');
|
|
405
409
|
}
|
|
406
410
|
const boundary = prepared.groups[batch.nextStatement - 1].endByte;
|
|
@@ -456,6 +460,7 @@ async function runPreparedDatabaseImport(prepared, config, dependencies) {
|
|
|
456
460
|
if (failure) {
|
|
457
461
|
const policyRefusal = failure.code === 'read_only_mode'
|
|
458
462
|
|| failure.code === 'plan_denied'
|
|
463
|
+
|| ['reads_exhausted', 'writes_exhausted', 'storage_exhausted'].includes(failure.code)
|
|
459
464
|
|| failure.status === 429;
|
|
460
465
|
const guidance = checkpointPublished && !suppressResume && !policyRefusal
|
|
461
466
|
? `\nLast completed position: batch ${completedBatches}, ${nextStatement} statements, ${completedSourceBytes} source bytes.\n${resumeLine(prepared.database, prepared.file, prepared.checkpointPath)}`
|
|
@@ -109,7 +109,51 @@ function git(sourceDir, args) {
|
|
|
109
109
|
}
|
|
110
110
|
return result.stdout.trim();
|
|
111
111
|
}
|
|
112
|
-
|
|
112
|
+
const NULL_DEFAULT_BRANCH_EVIDENCE = {
|
|
113
|
+
default_branch: null,
|
|
114
|
+
default_branch_sha: null,
|
|
115
|
+
commits_behind: null,
|
|
116
|
+
};
|
|
117
|
+
function defaultBranchEvidence(sourceDir, hasOrigin, hint) {
|
|
118
|
+
if (!hasOrigin || git(sourceDir, ['rev-parse', '--is-shallow-repository']) !== 'false') {
|
|
119
|
+
return NULL_DEFAULT_BRANCH_EVIDENCE;
|
|
120
|
+
}
|
|
121
|
+
let trackingRef = git(sourceDir, ['symbolic-ref', '--quiet', 'refs/remotes/origin/HEAD']);
|
|
122
|
+
if (trackingRef === null) {
|
|
123
|
+
// Only a genuinely absent origin/HEAD permits the conventional-name fallback.
|
|
124
|
+
// An unexpected direct ref is existing-but-invalid evidence, just like a stale
|
|
125
|
+
// symbolic target, and must not be silently replaced with a guess.
|
|
126
|
+
if (git(sourceDir, ['rev-parse', '--verify', 'refs/remotes/origin/HEAD']) !== null) {
|
|
127
|
+
return NULL_DEFAULT_BRANCH_EVIDENCE;
|
|
128
|
+
}
|
|
129
|
+
const candidates = ['main', 'master'].filter((branch) => git(sourceDir, ['rev-parse', '--verify', `refs/remotes/origin/${branch}^{commit}`]) !== null);
|
|
130
|
+
if (candidates.length !== 1) {
|
|
131
|
+
hint?.('Unable to determine origin default branch; run `git remote set-head origin -a`.');
|
|
132
|
+
return NULL_DEFAULT_BRANCH_EVIDENCE;
|
|
133
|
+
}
|
|
134
|
+
trackingRef = `refs/remotes/origin/${candidates[0]}`;
|
|
135
|
+
}
|
|
136
|
+
const prefix = 'refs/remotes/origin/';
|
|
137
|
+
if (!trackingRef.startsWith(prefix)) {
|
|
138
|
+
return NULL_DEFAULT_BRANCH_EVIDENCE;
|
|
139
|
+
}
|
|
140
|
+
const branch = displayValue(trackingRef.slice(prefix.length), 255);
|
|
141
|
+
const sha = shaValue(git(sourceDir, ['rev-parse', '--verify', `${trackingRef}^{commit}`]) ?? undefined);
|
|
142
|
+
if (!branch || !sha) {
|
|
143
|
+
return NULL_DEFAULT_BRANCH_EVIDENCE;
|
|
144
|
+
}
|
|
145
|
+
const counts = git(sourceDir, ['rev-list', '--left-right', '--count', `HEAD...${trackingRef}`]);
|
|
146
|
+
const match = counts?.match(/^(\d+)\s+(\d+)$/);
|
|
147
|
+
if (!match) {
|
|
148
|
+
return NULL_DEFAULT_BRANCH_EVIDENCE;
|
|
149
|
+
}
|
|
150
|
+
const behind = Number(match[2]);
|
|
151
|
+
if (!Number.isSafeInteger(behind) || behind < 0 || behind > 2_147_483_647) {
|
|
152
|
+
return NULL_DEFAULT_BRANCH_EVIDENCE;
|
|
153
|
+
}
|
|
154
|
+
return { default_branch: branch, default_branch_sha: sha, commits_behind: behind };
|
|
155
|
+
}
|
|
156
|
+
function localGitMetadata(sourceDir, hint) {
|
|
113
157
|
if (git(sourceDir, ['rev-parse', '--is-inside-work-tree']) !== 'true') {
|
|
114
158
|
return null;
|
|
115
159
|
}
|
|
@@ -119,6 +163,7 @@ function localGitMetadata(sourceDir) {
|
|
|
119
163
|
}
|
|
120
164
|
const status = git(sourceDir, ['status', '--porcelain=v1', '--untracked-files=all', '--', '.']);
|
|
121
165
|
const shortSha = shaValue(git(sourceDir, ['rev-parse', '--short=12', 'HEAD']) ?? undefined);
|
|
166
|
+
const remoteUrl = sanitizeRemoteUrl(git(sourceDir, ['config', '--get', 'remote.origin.url']) ?? undefined);
|
|
122
167
|
return {
|
|
123
168
|
metadata_source: 'git',
|
|
124
169
|
commit_sha: commitSha,
|
|
@@ -127,8 +172,9 @@ function localGitMetadata(sourceDir) {
|
|
|
127
172
|
tag: displayValue(git(sourceDir, ['describe', '--tags', '--exact-match', 'HEAD']) ?? undefined, 255),
|
|
128
173
|
commit_subject: displayValue(git(sourceDir, ['show', '-s', '--format=%s', 'HEAD']) ?? undefined, 500),
|
|
129
174
|
commit_author_date: authorDateValue(git(sourceDir, ['show', '-s', '--format=%aI', 'HEAD']) ?? undefined),
|
|
130
|
-
remote_url:
|
|
175
|
+
remote_url: remoteUrl,
|
|
131
176
|
dirty: status === null ? null : status !== '',
|
|
177
|
+
...defaultBranchEvidence(sourceDir, remoteUrl !== null, hint),
|
|
132
178
|
};
|
|
133
179
|
}
|
|
134
180
|
function baseCiMetadata(source, sha) {
|
|
@@ -142,6 +188,9 @@ function baseCiMetadata(source, sha) {
|
|
|
142
188
|
commit_author_date: null,
|
|
143
189
|
remote_url: null,
|
|
144
190
|
dirty: null,
|
|
191
|
+
default_branch: null,
|
|
192
|
+
default_branch_sha: null,
|
|
193
|
+
commits_behind: null,
|
|
145
194
|
};
|
|
146
195
|
}
|
|
147
196
|
function githubMetadata(environment) {
|
|
@@ -196,8 +245,8 @@ function bitbucketMetadata(environment) {
|
|
|
196
245
|
remote_url: sanitizeRemoteUrl(environment.BITBUCKET_GIT_HTTP_ORIGIN || environment.BITBUCKET_GIT_SSH_ORIGIN),
|
|
197
246
|
};
|
|
198
247
|
}
|
|
199
|
-
function collectSourceMetadata(sourceDir, environment = process.env) {
|
|
200
|
-
return localGitMetadata(path_1.default.resolve(sourceDir))
|
|
248
|
+
function collectSourceMetadata(sourceDir, environment = process.env, hint) {
|
|
249
|
+
return localGitMetadata(path_1.default.resolve(sourceDir), hint)
|
|
201
250
|
?? githubMetadata(environment)
|
|
202
251
|
?? gitlabMetadata(environment)
|
|
203
252
|
?? circleMetadata(environment)
|