@odla-ai/harness 0.5.0 → 0.5.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.
@@ -168,6 +168,7 @@ function parseSnapshot(value) {
168
168
  return { host, bindings, commands };
169
169
  }
170
170
  async function parseSource(value) {
171
+ const repositoryLimits = { maximumFiles: 1e5, maximumBytes: 80 * 1024 * 1024 };
171
172
  const snapshot = record(record(value)?.snapshot);
172
173
  if (!snapshot || typeof snapshot.repository !== "string" || typeof snapshot.commitSha !== "string" || typeof snapshot.treeDigest !== "string" || !Array.isArray(snapshot.files)) throw invalid("source");
173
174
  const files = snapshot.files.map((value2) => {
@@ -189,12 +190,12 @@ async function parseSource(value) {
189
190
  return { path: file.path, content: file.content };
190
191
  });
191
192
  const source2 = { repository: reference.repository, commitSha: reference.commitSha, files: referenceFiles };
192
- const referenceDigest = await (0, import_code.digestCodeRepositorySnapshot)(source2, { maximumFiles: 1e4, maximumBytes: 16 * 1024 * 1024 });
193
+ const referenceDigest = await (0, import_code.digestCodeRepositorySnapshot)(source2, repositoryLimits);
193
194
  if (referenceDigest !== reference.treeDigest) throw invalid("reference source digest");
194
195
  references.push({ alias: reference.alias, ...source2, treeDigest: referenceDigest });
195
196
  }
196
197
  const source = { repository: snapshot.repository, commitSha: snapshot.commitSha, files };
197
- const digest = await (0, import_code.digestCodeRepositorySnapshot)(source, { maximumFiles: 1e4, maximumBytes: 16 * 1024 * 1024 });
198
+ const digest = await (0, import_code.digestCodeRepositorySnapshot)(source, repositoryLimits);
198
199
  if (digest !== snapshot.treeDigest) throw invalid("source digest");
199
200
  return { ...source, treeDigest: digest, ...references.length ? { references } : {} };
200
201
  }
@@ -1266,8 +1267,11 @@ var import_node_os2 = require("os");
1266
1267
  var import_node_path7 = require("path");
1267
1268
  var RESERVED2 = /* @__PURE__ */ new Set([".git", ".odla", ".wrangler", "node_modules", "dist", "coverage"]);
1268
1269
  var SECRET2 = /^(?:\.env(?:\..+)?|\.dev\.vars|credentials(?:\..+)?\.json|dev-token(?:\..+)?\.json)$/i;
1270
+ var SOURCE_MAX_FILES = 1e5;
1271
+ var SOURCE_MAX_BYTES = 80 * 1024 * 1024;
1272
+ var SOURCE_SET_MAX_BYTES = 480 * 1024 * 1024;
1269
1273
  async function materializeCodeRuntimeSource(snapshot, tempRoot = (0, import_node_os2.tmpdir)()) {
1270
- if (!snapshot.files.length || snapshot.files.length > 1e4) throw new TypeError("Code source file count is invalid");
1274
+ if (!snapshot.files.length || snapshot.files.length > SOURCE_MAX_FILES) throw new TypeError("Code source file count is invalid");
1271
1275
  const root = await (0, import_promises6.mkdtemp)((0, import_node_path7.join)(tempRoot, "odla-code-source-"));
1272
1276
  const sourceDir = (0, import_node_path7.join)(root, "source");
1273
1277
  await (0, import_promises6.mkdir)(sourceDir);
@@ -1279,7 +1283,7 @@ async function materializeCodeRuntimeSource(snapshot, tempRoot = (0, import_node
1279
1283
  if (seen.has(file.path)) throw new TypeError("Code source repeats a path");
1280
1284
  seen.add(file.path);
1281
1285
  bytes += Buffer.byteLength(file.path) + Buffer.byteLength(file.content);
1282
- if (bytes > 16 * 1024 * 1024) throw new TypeError("Code source exceeds its byte bound");
1286
+ if (bytes > SOURCE_MAX_BYTES) throw new TypeError("Code source exceeds its byte bound");
1283
1287
  const target = (0, import_node_path7.resolve)(sourceDir, file.path);
1284
1288
  if (!target.startsWith(`${(0, import_node_path7.resolve)(sourceDir)}${import_node_path7.sep}`)) throw new TypeError("Code source path escapes its root");
1285
1289
  await (0, import_promises6.mkdir)((0, import_node_path7.dirname)(target), { recursive: true });
@@ -1287,14 +1291,14 @@ async function materializeCodeRuntimeSource(snapshot, tempRoot = (0, import_node
1287
1291
  }
1288
1292
  for (const reference of snapshot.references ?? []) {
1289
1293
  validateAlias(reference.alias);
1290
- if (!reference.files.length || reference.files.length > 1e4) throw new TypeError("Code reference file count is invalid");
1294
+ if (!reference.files.length || reference.files.length > SOURCE_MAX_FILES) throw new TypeError("Code reference file count is invalid");
1291
1295
  for (const file of reference.files) {
1292
1296
  validatePath(file.path);
1293
1297
  const path = `.odla-references/${reference.alias}/${file.path}`;
1294
1298
  if (seen.has(path)) throw new TypeError("Code reference repeats a path");
1295
1299
  seen.add(path);
1296
1300
  bytes += Buffer.byteLength(path) + Buffer.byteLength(file.content);
1297
- if (bytes > 80 * 1024 * 1024) throw new TypeError("Code source set exceeds its byte bound");
1301
+ if (bytes > SOURCE_SET_MAX_BYTES) throw new TypeError("Code source set exceeds its byte bound");
1298
1302
  const target = (0, import_node_path7.resolve)(sourceDir, path);
1299
1303
  if (!target.startsWith(`${(0, import_node_path7.resolve)(sourceDir)}${import_node_path7.sep}`)) throw new TypeError("Code reference path escapes its root");
1300
1304
  await (0, import_promises6.mkdir)((0, import_node_path7.dirname)(target), { recursive: true });
@@ -1320,7 +1324,7 @@ async function attachCodeRuntimeReferences(workspace, references) {
1320
1324
  validatePath(file.path);
1321
1325
  const path = `.odla-references/${reference.alias}/${file.path}`;
1322
1326
  bytes += Buffer.byteLength(path) + Buffer.byteLength(file.content);
1323
- if (bytes > 64 * 1024 * 1024) throw new TypeError("Code reference set exceeds its byte bound");
1327
+ if (bytes > SOURCE_SET_MAX_BYTES - SOURCE_MAX_BYTES) throw new TypeError("Code reference set exceeds its byte bound");
1324
1328
  for (const root of [workspace.baselineDir, workspace.workspaceDir]) {
1325
1329
  const target = (0, import_node_path7.resolve)(root, path);
1326
1330
  if (!target.startsWith(`${(0, import_node_path7.resolve)(root)}${import_node_path7.sep}`)) throw new TypeError("Code reference path escapes its root");
@@ -1370,7 +1374,10 @@ async function materializeCommandWorkspace(input) {
1370
1374
  trustedBaseDir: materialized.sourceDir,
1371
1375
  trustedBaseCommitSha: source.commitSha,
1372
1376
  checkpoint: codeCheckpointPayload(command.payload)
1373
- })).workspace : await stageWorkspace(materialized.sourceDir);
1377
+ })).workspace : await stageWorkspace(materialized.sourceDir, {
1378
+ maxFiles: SOURCE_MAX_FILES,
1379
+ maxBytes: SOURCE_SET_MAX_BYTES
1380
+ });
1374
1381
  return { workspace, sourceDigest: source.treeDigest, requestedLocal: null };
1375
1382
  } finally {
1376
1383
  await materialized.cleanup();