hammerkit 2.1.0-next.10 → 2.1.0-next.12
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/dashboard/assets/{graph-canvas-BFnEN5i0.js → graph-canvas-D6GMgkoe.js} +1 -1
- package/dist/dashboard/assets/index-BNq9j5Jo.js +23 -0
- package/dist/dashboard/assets/{index-Dt3ITvRO.css → index-DP3_hKOe.css} +1 -1
- package/dist/dashboard/index.html +2 -2
- package/dist/executer/archive-task-entry.js +1 -1
- package/dist/executer/deadline.js +63 -10
- package/dist/executer/event-cache.js +5 -1
- package/dist/executer/execute-work-task.js +15 -3
- package/dist/file/get-file-context.js +4 -7
- package/dist/harness/sandbox-client.js +29 -2
- package/dist/kubernetes/cluster-state.js +48 -14
- package/dist/kubernetes/ensure-persistent-data.js +14 -3
- package/dist/kubernetes/resources.js +5 -1
- package/dist/kubernetes/store-kubernetes-data.js +18 -3
- package/dist/planner/work-runtime-aggregate.js +1 -0
- package/dist/planner/work-runtime-docker.js +9 -5
- package/dist/planner/work-runtime-kubernetes.js +6 -4
- package/dist/planner/work-runtime-local.js +8 -4
- package/dist/remote/annotations.js +29 -3
- package/dist/remote/bundle.js +6 -8
- package/dist/remote/collect-bundle.js +3 -2
- package/dist/remote/remote-work-commands.js +161 -8
- package/dist/server/artifacts-api.js +56 -0
- package/dist/server/definitions-api.js +62 -8
- package/dist/server/executor.js +17 -0
- package/dist/server/keep-artifacts.js +230 -0
- package/dist/server/overview.js +67 -9
- package/dist/server/paging.js +167 -0
- package/dist/server/run-access.js +24 -0
- package/dist/server/run-artifacts.js +171 -0
- package/dist/server/run-worker.js +29 -0
- package/dist/server/runs.js +8 -0
- package/dist/server/sandbox-files.js +2 -7
- package/dist/server/sandboxes-api.js +54 -8
- package/dist/server/server-config.js +14 -0
- package/dist/server/server.js +122 -27
- package/dist/server/task-order.js +56 -0
- package/dist/utils/project-path.js +20 -0
- package/dist/utils/tar.js +37 -1
- package/package.json +1 -1
- package/dist/dashboard/assets/index-CE5PSB3y.js +0 -23
package/dist/server/server.js
CHANGED
|
@@ -18,6 +18,7 @@ const executor_1 = require("./executor");
|
|
|
18
18
|
const capacity_1 = require("./capacity");
|
|
19
19
|
const execute_docker_1 = require("../executer/execute-docker");
|
|
20
20
|
const timings_1 = require("./timings");
|
|
21
|
+
const task_order_1 = require("./task-order");
|
|
21
22
|
const kubernetes_backend_1 = require("./kubernetes-backend");
|
|
22
23
|
const run_plan_1 = require("./run-plan");
|
|
23
24
|
const run_source_environment_1 = require("./run-source-environment");
|
|
@@ -48,7 +49,11 @@ const get_cache_directory_1 = require("../optimizer/get-cache-directory");
|
|
|
48
49
|
const path_1 = require("path");
|
|
49
50
|
const checks_1 = require("./checks");
|
|
50
51
|
const checks_api_1 = require("./checks-api");
|
|
52
|
+
const run_artifacts_1 = require("./run-artifacts");
|
|
53
|
+
const artifacts_api_1 = require("./artifacts-api");
|
|
54
|
+
const run_access_1 = require("./run-access");
|
|
51
55
|
const overview_1 = require("./overview");
|
|
56
|
+
const paging_1 = require("./paging");
|
|
52
57
|
var discovery_2 = require("./discovery");
|
|
53
58
|
Object.defineProperty(exports, "DISCOVERY_PATH", { enumerable: true, get: function () { return discovery_2.DISCOVERY_PATH; } });
|
|
54
59
|
Object.defineProperty(exports, "SERVER_PROTOCOL", { enumerable: true, get: function () { return discovery_2.SERVER_PROTOCOL; } });
|
|
@@ -79,6 +84,8 @@ const HEARTBEAT_MS = 15000;
|
|
|
79
84
|
const MAX_WAIT_MS = 50000;
|
|
80
85
|
// how often checks older than `runs.checksKeep` are removed
|
|
81
86
|
const CHECK_SWEEP_MS = 6 * 60 * 60 * 1000;
|
|
87
|
+
// how often the outputs of runs that are over their time are removed
|
|
88
|
+
const ARTIFACT_SWEEP_MS = 60 * 60 * 1000;
|
|
82
89
|
// Server-sent events: `id` is the sequence number, so a client that lost the
|
|
83
90
|
// connection continues with Last-Event-ID (or ?after=) and misses nothing.
|
|
84
91
|
function streamEvents(registry, config, principal, id, req, res, url) {
|
|
@@ -89,7 +96,7 @@ function streamEvents(registry, config, principal, id, req, res, url) {
|
|
|
89
96
|
if (event.type === 'state' && (0, runs_1.isFinal)(event.state)) {
|
|
90
97
|
end();
|
|
91
98
|
}
|
|
92
|
-
}, accountsOf(config, principal));
|
|
99
|
+
}, (0, run_access_1.accountsOf)(config, principal));
|
|
93
100
|
if (!watch) {
|
|
94
101
|
(0, http_2.send)(res, 404, { error: 'not found' });
|
|
95
102
|
return;
|
|
@@ -122,18 +129,45 @@ async function handleRuns(config, registry, definitions, sources, sandboxes, pla
|
|
|
122
129
|
if (method === 'GET') {
|
|
123
130
|
// the results of each task are read one run at a time
|
|
124
131
|
const viewer = (0, overview_1.getViewer)(config, principal);
|
|
125
|
-
let filter;
|
|
132
|
+
let filter, page, values;
|
|
126
133
|
try {
|
|
127
134
|
filter = (0, overview_1.parseRunFilter)(url.searchParams, viewer.grant);
|
|
135
|
+
values = (0, paging_1.parseValues)(url.searchParams, overview_1.RUN_FIELDS);
|
|
136
|
+
page = values ? undefined : (0, paging_1.parsePage)(url.searchParams);
|
|
128
137
|
}
|
|
129
138
|
catch (e) {
|
|
130
139
|
(0, http_2.send)(res, e instanceof overview_1.FilterRefused ? 403 : 400, { error: e instanceof Error ? e.message : String(e) });
|
|
131
140
|
return true;
|
|
132
141
|
}
|
|
133
142
|
const runs = filter.scope === 'mine' ? registry.list(principal) : registry.all();
|
|
134
|
-
(
|
|
135
|
-
|
|
136
|
-
|
|
143
|
+
const list = (run) => listRun(registry, definitions, viewer, run);
|
|
144
|
+
try {
|
|
145
|
+
if (values) {
|
|
146
|
+
// a value of the field is counted over the runs the other filters let through
|
|
147
|
+
const { of, order } = (0, overview_1.runValues)(values.field);
|
|
148
|
+
const counted = (0, paging_1.countValues)((0, overview_1.filterRuns)(runs, viewer, (0, overview_1.withoutField)(filter, values.field)), of, values, order);
|
|
149
|
+
(0, http_2.send)(res, 200, (0, paging_1.answerPage)('values', counted));
|
|
150
|
+
}
|
|
151
|
+
else if (page) {
|
|
152
|
+
// newest first, as the registry keeps them
|
|
153
|
+
const found = (0, overview_1.filterRuns)(runs, viewer, filter);
|
|
154
|
+
const oldest = found[found.length - 1]?.createdAt;
|
|
155
|
+
const answered = (0, paging_1.pageByKey)(found, page, runKey);
|
|
156
|
+
(0, http_2.send)(res, 200, {
|
|
157
|
+
...(0, paging_1.answerPage)('runs', { ...answered, items: answered.items.map(list) }),
|
|
158
|
+
...(oldest ? { oldest } : {}),
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
(0, http_2.send)(res, 200, { runs: (0, overview_1.filterRuns)(runs, viewer, filter).map(list) });
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
catch (e) {
|
|
166
|
+
if (!(e instanceof paging_1.ListParamError)) {
|
|
167
|
+
throw e;
|
|
168
|
+
}
|
|
169
|
+
(0, http_2.send)(res, 400, { error: e.message });
|
|
170
|
+
}
|
|
137
171
|
}
|
|
138
172
|
else if (method === 'POST') {
|
|
139
173
|
await submitRun(config, registry, definitions, sources, sandboxes, planning, repos, endpointUrl, log, principal, req, res);
|
|
@@ -152,7 +186,7 @@ async function handleRuns(config, registry, definitions, sources, sandboxes, pla
|
|
|
152
186
|
return true;
|
|
153
187
|
}
|
|
154
188
|
const grant = (0, policy_1.getGrant)(config.entitlements, principal);
|
|
155
|
-
const run = registry.cancel(principal, id, accountsOf(config, principal), (up) => (0, service_runs_1.mayPublishEndpoints)(grant, up));
|
|
189
|
+
const run = registry.cancel(principal, id, (0, run_access_1.accountsOf)(config, principal), (up) => (0, service_runs_1.mayPublishEndpoints)(grant, up));
|
|
156
190
|
log(`cancel iss=${principal.iss} sub=${principal.sub} run=${id} found=${Boolean(run)}`);
|
|
157
191
|
run ? (0, http_2.send)(res, 200, answerRun(config, principal, run)) : (0, http_2.send)(res, 404, { error: 'not found' });
|
|
158
192
|
}
|
|
@@ -207,9 +241,8 @@ async function handleRuns(config, registry, definitions, sources, sandboxes, pla
|
|
|
207
241
|
(0, http_2.send)(res, 400, { error: e instanceof Error ? e.message : String(e) });
|
|
208
242
|
return true;
|
|
209
243
|
}
|
|
210
|
-
// an entitlement with `observe`
|
|
211
|
-
const logs =
|
|
212
|
-
((0, policy_1.getGrant)(config.entitlements, principal).observe ? registry.logsOf(id) : undefined);
|
|
244
|
+
// who may read the run reads its log, an entitlement with `observe` every run's
|
|
245
|
+
const logs = (0, run_access_1.findReadableRun)(config, registry, principal, id) ? registry.logsOf(id) : undefined;
|
|
213
246
|
// with the tasks, services and the server's own lines (`hammerkit`) the log has
|
|
214
247
|
logs
|
|
215
248
|
? (0, http_2.send)(res, 200, { ...(0, run_logs_1.readLogs)(logs.events, logs.index, query, logs.truncated), names: logs.index.names() })
|
|
@@ -232,7 +265,7 @@ async function handleRuns(config, registry, definitions, sources, sandboxes, pla
|
|
|
232
265
|
res.on('close', () => gone.abort());
|
|
233
266
|
const viewer = (0, overview_1.getViewer)(config, principal);
|
|
234
267
|
// an entitlement with `observe` reads every run as it is, without waiting
|
|
235
|
-
const run = (await registry.wait(principal, id, wait, accountsOf(config, principal), gone.signal)) ??
|
|
268
|
+
const run = (await registry.wait(principal, id, wait, (0, run_access_1.accountsOf)(config, principal), gone.signal)) ??
|
|
236
269
|
(viewer.grant.observe ? registry.peek(id) : undefined);
|
|
237
270
|
if (!gone.signal.aborted) {
|
|
238
271
|
const may = run && (0, overview_1.runActions)(viewer, run);
|
|
@@ -246,11 +279,6 @@ async function handleRuns(config, registry, definitions, sources, sandboxes, pla
|
|
|
246
279
|
}
|
|
247
280
|
return true;
|
|
248
281
|
}
|
|
249
|
-
// The accounts the caller uses: who approves a run on them follows and stops it.
|
|
250
|
-
function accountsOf(config, principal) {
|
|
251
|
-
const grant = (0, policy_1.getGrant)(config.entitlements, principal);
|
|
252
|
-
return (account) => (0, policy_1.canUse)(grant, account);
|
|
253
|
-
}
|
|
254
282
|
async function extendRun(config, registry, log, principal, id, req, res) {
|
|
255
283
|
const body = (await (0, http_2.readJson)(req));
|
|
256
284
|
let ttl;
|
|
@@ -351,6 +379,8 @@ function toRunResponse(run, queue, named = false, nameOf) {
|
|
|
351
379
|
...(queue ? { queue } : {}),
|
|
352
380
|
};
|
|
353
381
|
}
|
|
382
|
+
// where a page of runs ends: when the last run was created, and which it is
|
|
383
|
+
const runKey = (run) => [run.createdAt, run.id];
|
|
354
384
|
function listRun(registry, definitions, viewer, run) {
|
|
355
385
|
return (0, overview_1.toListedRun)(viewer, run, (0, overview_1.queuePlace)(registry, viewer, run), entryOf(definitions));
|
|
356
386
|
}
|
|
@@ -371,7 +401,7 @@ async function submitRun(config, registry, definitions, sources, sandboxes, plan
|
|
|
371
401
|
// an approval where they need one, never the owner's (run-retry.ts).
|
|
372
402
|
async function retryRun(config, registry, definitions, sources, sandboxes, planning, repos, endpointUrl, log, principal, id, res) {
|
|
373
403
|
const viewer = (0, overview_1.getViewer)(config, principal);
|
|
374
|
-
const run =
|
|
404
|
+
const run = (0, run_access_1.findReadableRun)(config, registry, principal, id);
|
|
375
405
|
if (!run) {
|
|
376
406
|
(0, http_2.send)(res, 404, { error: 'not found' });
|
|
377
407
|
return;
|
|
@@ -761,7 +791,7 @@ async function handle(api, verifier, req, res) {
|
|
|
761
791
|
* dashboard, which asks the same API for what its pages show (dashboard.ts).
|
|
762
792
|
*/
|
|
763
793
|
async function handleApi(api, principal, req, res, url) {
|
|
764
|
-
const { config, registry, gateway, definitions, proposals, sources, sandboxes, planning, repos, checks, capacity, log, } = api;
|
|
794
|
+
const { config, registry, gateway, definitions, proposals, sources, sandboxes, planning, repos, checks, artifacts, capacity, log, now, } = api;
|
|
765
795
|
const path = url.pathname;
|
|
766
796
|
if (await (0, accounts_api_1.handleAccounts)(config, log, principal, req, res, url)) {
|
|
767
797
|
return;
|
|
@@ -775,6 +805,9 @@ async function handleApi(api, principal, req, res, url) {
|
|
|
775
805
|
if (await (0, sandboxes_api_1.handleSandboxes)(config, sandboxes.registry, repos, log, principal, req, res, url)) {
|
|
776
806
|
return;
|
|
777
807
|
}
|
|
808
|
+
if (await (0, artifacts_api_1.handleArtifacts)(config, registry, artifacts, log, principal, req, res, url, now)) {
|
|
809
|
+
return;
|
|
810
|
+
}
|
|
778
811
|
if (await handleRuns(config, registry, definitions, sources, sandboxes, planning, repos, (host) => gateway?.url(host) ?? host, log, principal, req, res, url)) {
|
|
779
812
|
return;
|
|
780
813
|
}
|
|
@@ -810,22 +843,53 @@ async function handleApi(api, principal, req, res, url) {
|
|
|
810
843
|
if (!params.has('scope')) {
|
|
811
844
|
params.set('scope', 'visible');
|
|
812
845
|
}
|
|
813
|
-
|
|
846
|
+
// the text is looked for in the tasks, not in the runs they ran in
|
|
847
|
+
params.delete('q');
|
|
848
|
+
let filter, page, values, order;
|
|
849
|
+
const text = (0, paging_1.readText)(url.searchParams);
|
|
814
850
|
try {
|
|
815
851
|
filter = (0, overview_1.parseRunFilter)(params, viewer.grant);
|
|
852
|
+
values = (0, paging_1.parseValues)(url.searchParams, task_order_1.TASK_FIELDS);
|
|
853
|
+
page = values ? undefined : (0, paging_1.parsePage)(url.searchParams);
|
|
854
|
+
order = (0, task_order_1.parseTaskOrder)(url.searchParams);
|
|
816
855
|
}
|
|
817
856
|
catch (e) {
|
|
818
857
|
(0, http_2.send)(res, e instanceof overview_1.FilterRefused ? 403 : 400, { error: e instanceof Error ? e.message : String(e) });
|
|
819
858
|
return;
|
|
820
859
|
}
|
|
821
|
-
const
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
860
|
+
const statsOf = (over) => {
|
|
861
|
+
const runs = (0, overview_1.filterRuns)(registry.all(), viewer, over).map((run) => (0, overview_1.toListedRun)(viewer, run));
|
|
862
|
+
// where in the repository the build file of the last run is, as its version says
|
|
863
|
+
const tasks = (0, timings_1.getTaskStats)(runs, Date.now())
|
|
864
|
+
.map((stats) => {
|
|
865
|
+
const entry = stats.last.definition ? api.definitions.find(stats.last.definition)?.entry : undefined;
|
|
866
|
+
return entry ? { ...stats, last: { ...stats.last, entry } } : stats;
|
|
867
|
+
})
|
|
868
|
+
.filter((stats) => !text || (0, paging_1.hasText)([stats.repo, stats.task, stats.last.entry], text));
|
|
869
|
+
return { runs, tasks };
|
|
870
|
+
};
|
|
871
|
+
try {
|
|
872
|
+
if (values) {
|
|
873
|
+
const { sources, ...others } = filter;
|
|
874
|
+
void sources;
|
|
875
|
+
const counted = (0, paging_1.countValues)(statsOf(others).tasks, (stats) => [(0, task_order_1.taskSource)(stats)], values);
|
|
876
|
+
(0, http_2.send)(res, 200, (0, paging_1.answerPage)('values', counted));
|
|
877
|
+
return;
|
|
878
|
+
}
|
|
879
|
+
const { runs, tasks } = statsOf(filter);
|
|
880
|
+
const oldest = (0, timings_1.getOldestCounted)(runs);
|
|
881
|
+
const sorted = order ? (0, task_order_1.sortTasks)(tasks, order) : tasks;
|
|
882
|
+
(0, http_2.send)(res, 200, {
|
|
883
|
+
...(page ? (0, paging_1.answerPage)('tasks', (0, paging_1.pageByPosition)(sorted, page)) : { tasks: sorted }),
|
|
884
|
+
...(oldest ? { oldest } : {}),
|
|
885
|
+
});
|
|
886
|
+
}
|
|
887
|
+
catch (e) {
|
|
888
|
+
if (!(e instanceof paging_1.ListParamError)) {
|
|
889
|
+
throw e;
|
|
890
|
+
}
|
|
891
|
+
(0, http_2.send)(res, 400, { error: e.message });
|
|
892
|
+
}
|
|
829
893
|
return;
|
|
830
894
|
}
|
|
831
895
|
if (await (0, approvals_api_1.handleApprovals)(config, registry, log, principal, req, res, url)) {
|
|
@@ -850,7 +914,8 @@ async function startServer(config, environment, options = {}) {
|
|
|
850
914
|
const log = (line) => write(line.replace(/\p{Cc}/gu, '?').slice(0, 1000));
|
|
851
915
|
if (config.runtimes.includes('local') && config.backend.type === 'host') {
|
|
852
916
|
log('warning: the local runtime is allowed, local tasks run as the user of this server and read all it can read; ' +
|
|
853
|
-
'an account is then an approval class, not a credential boundary'
|
|
917
|
+
'an account is then an approval class, not a credential boundary, and the server keeps no outputs of its runs ' +
|
|
918
|
+
'(remote artifacts)');
|
|
854
919
|
}
|
|
855
920
|
// build files are read, planned and run as the server's runs see the world: the
|
|
856
921
|
// operator's accounts and the allowlisted environment, nothing of the server's own
|
|
@@ -930,6 +995,8 @@ async function startServer(config, environment, options = {}) {
|
|
|
930
995
|
if (config.backend.type === 'host' || config.entitlements.some((entitlement) => entitlement.sandboxes?.length)) {
|
|
931
996
|
await sandboxes.registry.load();
|
|
932
997
|
}
|
|
998
|
+
// a local task of a host runs as the user of this server: what it can write is never served
|
|
999
|
+
const localTasksOnHost = config.backend.type === 'host' && config.runtimes.includes('local');
|
|
933
1000
|
const executorOptions = {
|
|
934
1001
|
definitions,
|
|
935
1002
|
planning,
|
|
@@ -938,6 +1005,7 @@ async function startServer(config, environment, options = {}) {
|
|
|
938
1005
|
cache: (0, path_1.join)(storage, 'cache'),
|
|
939
1006
|
worker: options.worker,
|
|
940
1007
|
sandboxes: { ...sandboxes, network: config.sandboxes.network },
|
|
1008
|
+
localTasksOnHost,
|
|
941
1009
|
...(config.backend.type === 'host' && config.backend.capabilities
|
|
942
1010
|
? { capabilityRuntime: config.backend.capabilities.runtime }
|
|
943
1011
|
: {}),
|
|
@@ -958,6 +1026,11 @@ async function startServer(config, environment, options = {}) {
|
|
|
958
1026
|
void sweepChecks();
|
|
959
1027
|
const sweeping = setInterval(sweepChecks, CHECK_SWEEP_MS);
|
|
960
1028
|
sweeping.unref();
|
|
1029
|
+
const artifacts = new run_artifacts_1.ArtifactStore((0, path_1.join)(storage, 'artifacts'), {
|
|
1030
|
+
keep: (0, units_1.parseDuration)(config.runs.artifacts.keep),
|
|
1031
|
+
total: (0, units_1.parseSize)(config.runs.artifacts.total),
|
|
1032
|
+
localTasksOnHost,
|
|
1033
|
+
});
|
|
961
1034
|
const registry = new runs_1.RunRegistry({
|
|
962
1035
|
executor,
|
|
963
1036
|
maxConcurrent: config.runs.maxConcurrent,
|
|
@@ -984,12 +1057,31 @@ async function startServer(config, environment, options = {}) {
|
|
|
984
1057
|
.then(() => log(`checks run=${run.id} passed=[${passed.map((record) => record.task).join(',')}]`))
|
|
985
1058
|
.catch((e) => log(`the checks of run ${run.id} were not kept: ${e instanceof Error ? e.message : e}`));
|
|
986
1059
|
}
|
|
1060
|
+
// what the run kept counts against the total of all runs from now
|
|
1061
|
+
void sweepArtifacts();
|
|
1062
|
+
},
|
|
1063
|
+
artifacts: {
|
|
1064
|
+
directoryOf: (id) => artifacts.directoryOf(id),
|
|
1065
|
+
maxBytes: (0, units_1.parseSize)(config.runs.artifacts.maxBytes),
|
|
987
1066
|
},
|
|
988
1067
|
log,
|
|
989
1068
|
});
|
|
1069
|
+
const now = options.now ?? Date.now;
|
|
1070
|
+
// what is over its time goes within the hour, what is over the total when a run ends
|
|
1071
|
+
const sweepArtifacts = () => artifacts
|
|
1072
|
+
.sweep((id) => registry.peek(id), now())
|
|
1073
|
+
.then((removed) => {
|
|
1074
|
+
if (removed.length > 0) {
|
|
1075
|
+
log(`removed the outputs of ${removed.length} runs: ${removed.join(', ')}`);
|
|
1076
|
+
}
|
|
1077
|
+
})
|
|
1078
|
+
.catch((e) => log(`the outputs of old runs could not be removed: ${e instanceof Error ? e.message : e}`));
|
|
1079
|
+
const sweepingArtifacts = setInterval(sweepArtifacts, ARTIFACT_SWEEP_MS);
|
|
1080
|
+
sweepingArtifacts.unref();
|
|
990
1081
|
// the executor hears which service runs sleep with their volumes kept, and removes what it
|
|
991
1082
|
// kept for any other (RunExecutor.restored)
|
|
992
1083
|
await registry.restore();
|
|
1084
|
+
void sweepArtifacts();
|
|
993
1085
|
const proposals = new proposals_1.ProposalRegistry({
|
|
994
1086
|
maxWaiting: config.approvals.maxWaiting,
|
|
995
1087
|
timeout: (0, units_1.parseDuration)(config.approvals.timeout),
|
|
@@ -1025,8 +1117,10 @@ async function startServer(config, environment, options = {}) {
|
|
|
1025
1117
|
planning,
|
|
1026
1118
|
repos,
|
|
1027
1119
|
checks,
|
|
1120
|
+
artifacts,
|
|
1028
1121
|
capacity,
|
|
1029
1122
|
log,
|
|
1123
|
+
now,
|
|
1030
1124
|
};
|
|
1031
1125
|
await gateway?.load();
|
|
1032
1126
|
sandboxes.registry.useRuns({
|
|
@@ -1126,6 +1220,7 @@ async function startServer(config, environment, options = {}) {
|
|
|
1126
1220
|
},
|
|
1127
1221
|
close: async () => {
|
|
1128
1222
|
clearInterval(sweeping);
|
|
1223
|
+
clearInterval(sweepingArtifacts);
|
|
1129
1224
|
proposals.close();
|
|
1130
1225
|
await registry.close();
|
|
1131
1226
|
await new Promise((resolve, reject) => {
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sortTasks = exports.parseTaskOrder = exports.taskSource = exports.TASK_FIELDS = void 0;
|
|
4
|
+
const paging_1 = require("./paging");
|
|
5
|
+
// what GET /v1/tasks?values= answers the values of: where the tasks ran from
|
|
6
|
+
exports.TASK_FIELDS = ['source'];
|
|
7
|
+
// where the runs of a task are from, as the source filter of the runs names it
|
|
8
|
+
function taskSource(stats) {
|
|
9
|
+
return stats.repo === 'an upload' ? 'upload' : stats.repo;
|
|
10
|
+
}
|
|
11
|
+
exports.taskSource = taskSource;
|
|
12
|
+
// of its runs, how many came from the cache, and how many ended well (cached passed before)
|
|
13
|
+
const rate = (part, stats) => (stats.runs ? part / stats.runs : undefined);
|
|
14
|
+
// what `sort` of GET /v1/tasks orders by: the columns of the Tasks page
|
|
15
|
+
const SORT_BY = {
|
|
16
|
+
task: (stats) => stats.task,
|
|
17
|
+
last: (stats) => Date.parse(stats.last.at),
|
|
18
|
+
runs: (stats) => stats.runs,
|
|
19
|
+
cache: (stats) => rate(stats.cached, stats),
|
|
20
|
+
success: (stats) => rate(stats.runs - stats.failed, stats),
|
|
21
|
+
median: (stats) => stats.medianMs,
|
|
22
|
+
p90: (stats) => stats.p90Ms,
|
|
23
|
+
total: (stats) => stats.totalMs,
|
|
24
|
+
};
|
|
25
|
+
// `sort` and `order` (asc or desc, desc when left out): undefined when the caller names no sort.
|
|
26
|
+
function parseTaskOrder(params) {
|
|
27
|
+
const sort = params.get('sort');
|
|
28
|
+
if (sort === null) {
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
if (!(sort in SORT_BY)) {
|
|
32
|
+
throw new paging_1.ListParamError(`sort: one of ${Object.keys(SORT_BY).join(', ')}`);
|
|
33
|
+
}
|
|
34
|
+
const order = params.get('order') ?? 'desc';
|
|
35
|
+
if (order !== 'asc' && order !== 'desc') {
|
|
36
|
+
throw new paging_1.ListParamError('order: asc or desc');
|
|
37
|
+
}
|
|
38
|
+
return { sort, order };
|
|
39
|
+
}
|
|
40
|
+
exports.parseTaskOrder = parseTaskOrder;
|
|
41
|
+
// The tasks in that order, those without a value last, and by repository and name when equal.
|
|
42
|
+
function sortTasks(tasks, { sort, order }) {
|
|
43
|
+
const value = SORT_BY[sort];
|
|
44
|
+
return [...tasks].sort((a, b) => {
|
|
45
|
+
const x = value(a);
|
|
46
|
+
const y = value(b);
|
|
47
|
+
if (x === undefined || y === undefined) {
|
|
48
|
+
return x === y ? tie(a, b) : x === undefined ? 1 : -1;
|
|
49
|
+
}
|
|
50
|
+
const compared = typeof x === 'number' && typeof y === 'number' ? x - y : String(x).localeCompare(String(y));
|
|
51
|
+
return (order === 'asc' ? compared : -compared) || tie(a, b);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
exports.sortTasks = sortTasks;
|
|
55
|
+
const tie = (a, b) => a.repo.localeCompare(b.repo) || a.task.localeCompare(b.task);
|
|
56
|
+
//# sourceMappingURL=task-order.js.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isRelativePath = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* A path relative to a root (of a project, a bundle, a sandbox), as the API and the CLI take
|
|
6
|
+
* it: at most `maxLength` characters, `/` between names, no `.` or `..` or empty name, no
|
|
7
|
+
* backslash, no NUL, nothing absolute (`/x`, `C:x`). The one rule every path an input names
|
|
8
|
+
* is checked by, so the places that check it can not drift apart.
|
|
9
|
+
*/
|
|
10
|
+
function isRelativePath(path, maxLength) {
|
|
11
|
+
return (path.length > 0 &&
|
|
12
|
+
path.length <= maxLength &&
|
|
13
|
+
!path.startsWith('/') &&
|
|
14
|
+
!/^[A-Za-z]:/.test(path) &&
|
|
15
|
+
!path.includes('\\') &&
|
|
16
|
+
!path.includes('\0') &&
|
|
17
|
+
!path.split('/').some((part) => part === '' || part === '.' || part === '..'));
|
|
18
|
+
}
|
|
19
|
+
exports.isRelativePath = isRelativePath;
|
|
20
|
+
//# sourceMappingURL=project-path.js.map
|
package/dist/utils/tar.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.onlyBelow = exports.extractOutput = exports.packArchive = void 0;
|
|
3
|
+
exports.onlyBelow = exports.extractOutput = exports.measureArchive = exports.packArchive = void 0;
|
|
4
|
+
const fs_1 = require("fs");
|
|
4
5
|
const tar_1 = require("tar");
|
|
5
6
|
const path_1 = require("path");
|
|
6
7
|
function packArchive(options, files) {
|
|
@@ -34,6 +35,41 @@ const NOT_PACKED = '\0';
|
|
|
34
35
|
function isExact(key) {
|
|
35
36
|
return key.split(':').every((part) => Number.isSafeInteger(Number(part)));
|
|
36
37
|
}
|
|
38
|
+
// The entries of an archive and the bytes of their content, unpacked, measured before anything
|
|
39
|
+
// is extracted from it. Reading stops at the first entry that takes it past `limit`, so what
|
|
40
|
+
// is returned is then more than the limit, and the rest of the archive is not read.
|
|
41
|
+
function measureArchive(file, limit) {
|
|
42
|
+
return new Promise((resolve, reject) => {
|
|
43
|
+
const measured = { entries: 0, bytes: 0 };
|
|
44
|
+
let done = false;
|
|
45
|
+
const source = (0, fs_1.createReadStream)(file);
|
|
46
|
+
const parser = new tar_1.Parser({
|
|
47
|
+
onReadEntry: (entry) => {
|
|
48
|
+
if (done) {
|
|
49
|
+
entry.resume();
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
measured.entries++;
|
|
53
|
+
measured.bytes += entry.size ?? 0;
|
|
54
|
+
entry.resume();
|
|
55
|
+
if (measured.entries > limit.entries || measured.bytes > limit.bytes) {
|
|
56
|
+
done = true;
|
|
57
|
+
source.unpipe(parser);
|
|
58
|
+
source.destroy();
|
|
59
|
+
resolve({ ...measured });
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
parser.on('end', () => {
|
|
64
|
+
done = true;
|
|
65
|
+
resolve({ ...measured });
|
|
66
|
+
});
|
|
67
|
+
parser.on('error', reject);
|
|
68
|
+
source.on('error', reject);
|
|
69
|
+
source.pipe(parser);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
exports.measureArchive = measureArchive;
|
|
37
73
|
// Extracts the archive of one output (a path relative to `cwd`) into `cwd`. An archive
|
|
38
74
|
// comes from a cache another run, or whoever writes to the cache backend, filled, so only
|
|
39
75
|
// entries of that output are taken: one beside it (another output, a source of the task, a
|
package/package.json
CHANGED