fix(share): an unconfirmed share only finishes a first share it can recognize (#8313)

A folder's review record can name a project with no finished share. When
no host confirmed that review, shareForReview now goes on only if the
project is as an unfinished first share leaves it: no ready version, its
link never turned off, and private or already set to this share's
audience. Anything else is refused with review_project_changed before
any audience change, link reopening or upload, and the record stays as
it is.
This commit is contained in:
Michael Wang
2026-11-20 20:09:04 +00:00
committed by GitHub
parent d8d45f481b
commit d3d3350d41
2 changed files with 68 additions and 2 deletions
+20 -2
View File
@@ -447,8 +447,25 @@ async function registerOnce(client, projectPath, record, title) {
* @param {ReviewClient} client @param {ProjectDTO} project */
async function unused(client, project) {
if (project.latest_ready_version_id) return false;
const share = await readShare(client, project.project_id);
return share.access_mode === "private" && !share.revoked;
return untouched(project, await readShare(client, project.project_id));
}
/** A project as an unfinished first share leaves it: no ready version, its link never turned off, and private, or set
* to this share's audience already when only the reply to that change was lost.
* @param {ProjectDTO} project @param {ShareDTO} share @param {import("./types/share.js").AccessMode} [audience] */
const untouched = (project, share, audience) =>
!project.latest_ready_version_id &&
!share.revoked &&
(share.access_mode === "private" || share.access_mode === audience);
/** With no review a host confirmed, a record's project that no share finished names nothing the person agreed to: only
* a first share that stopped before it finished goes on. Anything else is refused, and the record stays as it is.
* @param {ReviewClient} client @param {ReviewRecord} read @param {ShareDTO} share
* @param {import("./types/share.js").AccessMode} [audience] */
async function assertUnfinished(client, read, share, audience) {
if (!read.projectId || read.opened) return;
if (!untouched(await client.project(read.projectId), share, audience))
throw new ReviewFailed(409, "review_project_changed");
}
/** A space refused at registration. Only one picked before the workspace changed is replaced by the next press;
@@ -485,6 +502,7 @@ export const shareForReview = ({
if (!read.projectId) await writeJsonAtomic(recordPath(projectPath), record);
const share = await readShare(client, id, projectPath);
if (takenDown(share)) return shown(client, share);
if (confirmed === undefined) await assertUnfinished(client, read, share, audience);
if (!record.opened || share.revoked) await beforeOpen?.(id);
return openLink(client, projectPath, record, id, share, audience).then(
(opened) => shown(client, opened),
+48
View File
@@ -69,6 +69,7 @@ function client() {
},
signedInEmail: async () => "owner@example.com",
share: async () => dto,
project: async () => ({ project_id: "p1", latest_ready_version_id: null }),
};
}
test("a lost registration response retries the persisted operation and identity", async (t) => {
@@ -748,6 +749,7 @@ function existingReview({ ready = "v1", access = "team", revoked = true, created
},
signedInEmail: async () => "owner@example.com",
share: async () => share,
project: async () => ({ project_id: "existing", latest_ready_version_id: ready }),
updateShare: write("updateShare"),
linkOn: write("linkOn"),
createExport: write("createExport"),
@@ -833,3 +835,49 @@ test("a share confirmed for one review refuses a record that now names another",
assert.equal((await reviewRecord(dir)).opened, false);
}
});
const unopened = { studioProjectId: "existing-studio", projectId: "existing", opened: false };
for (const [name, review] of [
["once it has a version", { access: "private", revoked: false }],
["once its audience was set", { ready: null, revoked: false }],
["once its link was turned off", { ready: null, access: "private" }],
]) {
test(`an unconfirmed share refuses a record's unopened review ${name}`, async (t) => {
const dir = await recordFolder(t, unopened);
const api = existingReview(review);
const prepared = [];
await assert.rejects(
shareForReview({
projectPath: dir,
title: "Video",
client: api,
audience: "public",
beforeOpen: async (id) => void prepared.push(id),
}),
{ status: 409, reason: "review_project_changed" },
);
assert.deepEqual(api.registrations, []);
assert.deepEqual(api.writes, []);
assert.deepEqual(prepared, []);
const saved = JSON.parse(await readFile(join(dir, ".hyperframes/review.json"), "utf8"));
assert.deepEqual(saved, unopened);
});
}
for (const [name, access, writes] of [
["before its audience was set", "private", ["updateShare"]],
["after only the reply to its audience was lost", "public", []],
]) {
test(`an unconfirmed share finishes a first share that stopped ${name}`, async (t) => {
const dir = await recordFolder(t, unopened);
const api = existingReview({ ready: null, access, revoked: false });
await shareForReview({ projectPath: dir, title: "Video", client: api, audience: "public" });
assert.deepEqual(
api.writes.map(([call]) => call),
writes,
);
const after = await reviewRecord(dir);
assert.equal(after.projectId, "existing");
assert.equal(after.opened, true);
});
}