Repository navigation
Document licensing, security, and SumUp; improve local precommit runs #1918
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 12 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
5c4194e
Correct project documentation and license
stefan-burke 9bcd26f
Record SumUp scheduled-finalize follow-up in TODO
stefan-burke 43c6922
Describe webhook validation per provider in payments doc
stefan-burke 4475f3d
Merge origin/main; cap local precommit test workers to (threads/2)-1
stefan-burke 153916d
Wait for another precommit run to finish before starting
stefan-burke 1f7a198
Reduce precommit lock complexity and sort imports
stefan-burke d561fa6
fix(precommit): address all Codex review findings on lock/workers
stefan-burke c8167bc
fix(precommit): use process-owned advisory lock
stefan-burke 8e0523c
docs: route SumUp polling through shared processor
stefan-burke f4bf464
test(precommit): isolate check and push ordering
stefan-burke ae7a97c
fix(precommit): validate overrides and strengthen lock test
stefan-burke 8a574ed
refactor(precommit): remove review leftovers
stefan-burke 5f8854a
fix(precommit): share a user-scoped lock
stefan-burke 6188162
test(precommit): cover failure cleanup paths
stefan-burke 633305a
test(precommit): cover the shared lock wrapper
stefan-burke File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| /** | ||
| * Run the heavy checks under the cross-worktree lock, then release it before | ||
| * the optional push prompt. CI jobs are already isolated and skip the lock. | ||
| */ | ||
| export const runChecksBeforePush = async ( | ||
| ci: boolean, | ||
| checks: () => Promise<void>, | ||
| push: () => Promise<void>, | ||
| lock: (task: () => Promise<void>) => Promise<void>, | ||
| ): Promise<void> => { | ||
| if (ci) await checks(); | ||
| else await lock(checks); | ||
| await push(); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| import { join } from "node:path"; | ||
| import { expect } from "@std/expect"; | ||
| import { afterEach, beforeEach, describe, it as test } from "@std/testing/bdd"; | ||
| import { stub } from "@std/testing/mock"; | ||
| import { removeIfPresent } from "#scripts/cleanup.ts"; | ||
| import { withFileLock } from "#scripts/lock-file.ts"; | ||
|
|
||
| const LOCK_PATH = join( | ||
| Deno.env.get("TMPDIR") ?? "/tmp", | ||
| `chobble-tickets-file-lock-test-${Deno.pid}-${Date.now()}.lock`, | ||
| ); | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
|
|
||
| const HOLD_LOCK_SCRIPT = ` | ||
| const file = await Deno.open(Deno.args[0], { | ||
| create: true, | ||
| read: true, | ||
| write: true, | ||
| }); | ||
| await file.lock(); | ||
| await Deno.stdout.write(new TextEncoder().encode("locked\\n")); | ||
| await Deno.stdin.read(new Uint8Array(1)); | ||
| file.close(); | ||
| `; | ||
|
|
||
| const EXIT_WITH_LOCK_SCRIPT = ` | ||
| const file = await Deno.open(Deno.args[0], { | ||
| create: true, | ||
| read: true, | ||
| write: true, | ||
| }); | ||
| await file.lock(); | ||
| await Deno.stdout.write(new TextEncoder().encode("locked\\n")); | ||
| Deno.exit(0); | ||
| `; | ||
|
|
||
| const startHolder = ( | ||
| script: string, | ||
| stdin: "piped" | "null" = "piped", | ||
| ): Deno.ChildProcess => | ||
| new Deno.Command(Deno.execPath(), { | ||
| args: ["eval", script, "--", LOCK_PATH], | ||
| stdin, | ||
| stdout: "piped", | ||
| }).spawn(); | ||
|
|
||
| const waitUntilLocked = async (child: Deno.ChildProcess): Promise<void> => { | ||
| const reader = child.stdout.getReader(); | ||
| try { | ||
| const { value } = await reader.read(); | ||
| expect(new TextDecoder().decode(value)).toBe("locked\n"); | ||
| } finally { | ||
| await reader.cancel(); | ||
| reader.releaseLock(); | ||
| } | ||
| }; | ||
|
|
||
| const releaseHolder = async (child: Deno.ChildProcess): Promise<void> => { | ||
| const writer = child.stdin.getWriter(); | ||
| await writer.write(new Uint8Array([1])); | ||
| await writer.close(); | ||
| await child.status; | ||
| }; | ||
|
|
||
| describe("withFileLock", () => { | ||
| beforeEach(() => removeIfPresent(LOCK_PATH)); | ||
| afterEach(() => removeIfPresent(LOCK_PATH)); | ||
|
|
||
| test("runs the task and returns its value", async () => { | ||
| await expect( | ||
| withFileLock(LOCK_PATH, () => Promise.resolve("checked")), | ||
| ).resolves.toBe("checked"); | ||
| }); | ||
|
|
||
| test("waits for a lock held by another process", async () => { | ||
| const holder = startHolder(HOLD_LOCK_SCRIPT); | ||
| await waitUntilLocked(holder); | ||
|
|
||
| const lockAttempted = Promise.withResolvers<void>(); | ||
| const open = Deno.open; | ||
| const openStub = stub( | ||
| Deno, | ||
| "open", | ||
| async ( | ||
| path: string | URL, | ||
| options?: Deno.OpenOptions, | ||
| ): Promise<Deno.FsFile> => { | ||
| const file = await open(path, options); | ||
| const lock = file.lock.bind(file); | ||
| file.lock = (exclusive?: boolean): Promise<void> => { | ||
| lockAttempted.resolve(); | ||
| return lock(exclusive); | ||
| }; | ||
| return file; | ||
| }, | ||
| ); | ||
|
|
||
| let ran = false; | ||
| let waiting: Promise<void> = Promise.resolve(); | ||
| try { | ||
| waiting = withFileLock(LOCK_PATH, async () => { | ||
| ran = true; | ||
| }); | ||
| await lockAttempted.promise; | ||
| expect(ran).toBe(false); | ||
| } finally { | ||
| openStub.restore(); | ||
| await releaseHolder(holder); | ||
| } | ||
|
|
||
| await waiting; | ||
| expect(ran).toBe(true); | ||
| }); | ||
|
|
||
| test("acquires after a holder exits without unlocking", async () => { | ||
| const holder = startHolder(EXIT_WITH_LOCK_SCRIPT, "null"); | ||
| await waitUntilLocked(holder); | ||
| await holder.status; | ||
|
|
||
| await expect( | ||
| withFileLock(LOCK_PATH, () => Promise.resolve("recovered")), | ||
| ).resolves.toBe("recovered"); | ||
| }); | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.