hammerkit 2.2.0-next.8 → 2.2.0-next.9

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.
@@ -259,7 +259,9 @@ function isRead(action, method) {
259
259
  // A sandbox as the caller sees it, and the run that holds it: their own without its owner,
260
260
  // one of somebody else (who observes) with whose it is, as a run of somebody else names it.
261
261
  function view(config, sandboxes, principal, sandbox) {
262
- const { owner, ...visible } = sandbox;
262
+ const { owner, origin, ...visible } = sandbox;
263
+ // the origin is the server's own record of the sandbox: not for the caller to see
264
+ void origin;
263
265
  const run = sandboxes.holder(sandbox.id);
264
266
  const mine = owner.iss === principal.iss && owner.sub === principal.sub;
265
267
  const name = owner.name ?? (0, policy_1.subjectName)(config.entitlements, owner);
@@ -222,6 +222,7 @@ class SandboxRegistry {
222
222
  repo,
223
223
  ref,
224
224
  commit,
225
+ origin: { branch: ref, commit },
225
226
  bytes,
226
227
  createdAt: at,
227
228
  lastUsedAt: at,
@@ -293,10 +294,16 @@ class SandboxRegistry {
293
294
  }
294
295
  /**
295
296
  * Commits the changes of a sandbox as its owner and pushes them to a branch the operator
296
- * allows (`sources[].push.branches`). The branch must not exist yet, or be one this
297
- * sandbox pushed and still at what it pushed: a sandbox never writes over somebody
298
- * else's work. The sandbox is at the pushed commit afterwards, so its changes are what
299
- * is not pushed yet and the next push to the branch adds a commit to it.
297
+ * allows (`sources[].push.branches`).
298
+ *
299
+ * The branch must not exist yet, or be one of these, and still be at the commit the
300
+ * sandbox last pushed to it or was created at:
301
+ * - a branch this sandbox pushed;
302
+ * - the branch the sandbox was created from, but not one it only fetched.
303
+ *
304
+ * A sandbox never writes over somebody else's work. Each push is a fast-forward with a
305
+ * lease on the commit it read. The sandbox is at the pushed commit afterwards, so its
306
+ * changes are what is not pushed yet, and the next push to the branch adds a commit to it.
300
307
  */
301
308
  // `allowed` are the branches the owner's entitlements let them push to from a sandbox of
302
309
  // its repository
@@ -331,10 +338,12 @@ class SandboxRegistry {
331
338
  throw new SandboxError(502, repos.scrub(e, read.values).message);
332
339
  }
333
340
  const pushed = sandbox.pushed?.[branch];
334
- if (current && current !== pushed) {
335
- throw new SandboxError(409, pushed
336
- ? `${branch} moved since this sandbox pushed it, push to a new branch`
337
- : `${branch} exists and this sandbox did not push it, push to a new branch`);
341
+ // the branch a sandbox was created from is its own until it moves
342
+ const created = sandbox.origin?.branch === branch;
343
+ // until the sandbox pushes it: after that, only what it pushed last is its own
344
+ const own = !pushed && created && current === sandbox.origin?.commit;
345
+ if (current && current !== pushed && !own) {
346
+ throw new SandboxError(409, refusedBranch(branch, pushed, created));
338
347
  }
339
348
  let write;
340
349
  try {
@@ -578,6 +587,16 @@ class SandboxRegistry {
578
587
  }
579
588
  }
580
589
  exports.SandboxRegistry = SandboxRegistry;
590
+ // why a branch that exists is not one the sandbox may push to
591
+ function refusedBranch(branch, pushed, created) {
592
+ if (pushed) {
593
+ return `${branch} moved since this sandbox pushed it, push to a new branch`;
594
+ }
595
+ if (created) {
596
+ return `${branch} moved since this sandbox started, push to a new branch`;
597
+ }
598
+ return `${branch} exists and this sandbox did not push it, push to a new branch`;
599
+ }
581
600
  function owns(owner, sandbox) {
582
601
  const of = 'owner' in sandbox ? sandbox.owner : sandbox;
583
602
  return of.iss === owner.iss && of.sub === owner.sub;
@@ -591,6 +610,7 @@ function copy(sandbox) {
591
610
  ...sandbox,
592
611
  owner: { ...sandbox.owner },
593
612
  ...(sandbox.pushed ? { pushed: { ...sandbox.pushed } } : {}),
613
+ ...(sandbox.origin ? { origin: { ...sandbox.origin } } : {}),
594
614
  };
595
615
  }
596
616
  //# sourceMappingURL=sandboxes.js.map
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "hammerkit",
3
3
  "description": "Containerized build tool with incremental caching that runs the same build file locally, in Docker and on Kubernetes.",
4
- "version": "2.2.0-next.8",
4
+ "version": "2.2.0-next.9",
5
5
  "keywords": [
6
6
  "build",
7
7
  "build-tool",