Skip to content

Commit d545231

Browse files
committed
🧪 Watch the held connection close, and order cleanup against it
A12's teardown evidence. The fixture now reports, without argument or value, that a held authenticated connection has closed, and that report goes into the same sequence the invocation's own teardown writes to. What it pins is the thing that must not happen: an authentication artifact removed while an authenticated connection is still open. The remote's own view of that connection ending sits before the removal of the launcher and the marker, and asserting only `released → removed` could not have told the difference. It does not pin the credential reference against the connection. That reference is dropped in the same turn as the kill, while the remote learns of the closed socket on a later turn of this process's loop — I asserted the exact triple first and it failed two runs in three, which is a scheduling accident rather than a contract. Neither step touches the filesystem or the network, and the launcher and the marker outlive neither. Five consecutive runs of the assertion that remains are stable. Remaining: A14, then A10. Refs #522
1 parent 3dc4320 commit d545231

2 files changed

Lines changed: 44 additions & 8 deletions

File tree

‎packages/workflow/tests/ambient-authentication.test.ts‎

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -864,10 +864,10 @@ describe("workflow ambient authentication cancellation", () => {
864864
* is a claim about the whole machine, and two concurrent invocations would
865865
* each see the other's.
866866
*/
867-
function watching() {
867+
function watching(sequence: string[] = []) {
868868
const opened: string[] = [];
869869
const released: string[] = [];
870-
const steps: string[] = [];
870+
const steps = sequence;
871871
return {
872872
observe: {
873873
opened: (directory: string) => opened.push(directory),
@@ -940,6 +940,9 @@ describe("workflow ambient authentication cancellation", () => {
940940
// that a real Git child has a real connection open to a server that proved
941941
// the credential and will not answer. Suspending before `git()` would stop
942942
// before any of that exists.
943+
// One sequence, written to by the remote and by the invocation's own
944+
// teardown, so what is proved is their order rather than each alone.
945+
const sequence: string[] = [];
943946
const served = yield* useGitHttpRemote({
944947
remote: bare,
945948
label: "first",
@@ -951,6 +954,7 @@ describe("workflow ambient authentication cancellation", () => {
951954
}
952955
return false;
953956
},
957+
closed: () => sequence.push("transport-closed"),
954958
});
955959
const home = yield* useInvokingHome([{ host: served.host, path: REPOSITORY, ...FIRST }]);
956960
const source = document(
@@ -962,7 +966,7 @@ describe("workflow ambient authentication cancellation", () => {
962966

963967
yield* withStorage(root, function* () {
964968
const database = yield* createRun();
965-
const watcher = watching();
969+
const watcher = watching(sequence);
966970
const recorded = tracked(
967971
denoGitAuthentication({
968972
ambient: home.ambient,
@@ -996,10 +1000,30 @@ describe("workflow ambient authentication cancellation", () => {
9961000
expect(yield* retainedRepositories(database)).toHaveLength(0);
9971001
expect(watcher.surviving()).toEqual([]);
9981002

999-
// Teardown released the credential reference and then removed what the
1000-
// invocation had made, in that order: a launcher or a marker outliving
1001-
// the reference they belong to would be state nobody owns.
1002-
expect(watcher.steps()).toEqual(["released", "removed"]);
1003+
// The whole order, pinned. What must not happen is an authentication
1004+
// artifact being removed while an authenticated connection is still open,
1005+
// and the remote's own view of that connection ending sits before the
1006+
// removal here.
1007+
//
1008+
// `released` is first because it is an in-memory reference dropped in the
1009+
// same turn as the kill, while the remote learns of the closed socket on a
1010+
// later turn of this process's loop — the transport is already gone when
1011+
// it is recorded, not still running. Nothing between the two touches the
1012+
// filesystem or the network.
1013+
// What must not happen is an authentication artifact being removed while
1014+
// an authenticated connection is still open, so the remote's own view of
1015+
// that connection ending is placed before the removal.
1016+
//
1017+
// The credential reference is dropped in the same turn as the kill, and
1018+
// the remote learns of the closed socket on a later turn of this process's
1019+
// loop — the two are not orderable against each other, and asserting an
1020+
// order between them would be asserting a scheduling accident. Neither
1021+
// touches the filesystem or the network, and the launcher and the marker
1022+
// outlive neither.
1023+
expect(sequence).toContain("transport-closed");
1024+
expect(sequence).toContain("released");
1025+
expect(sequence.indexOf("transport-closed")).toBeLessThan(sequence.indexOf("removed"));
1026+
expect(sequence.indexOf("released")).toBeLessThan(sequence.indexOf("removed"));
10031027
expect(watcher.surviving()).toEqual([]);
10041028

10051029
// And the attempt after it acquires again rather than continuing under an

‎packages/workflow/tests/support/git-http.ts‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,16 @@ export interface GitHttpOptions {
9595
* server having refused anything.
9696
*/
9797
readonly redirect?: (request: ServedGitRequest) => string | undefined;
98+
/**
99+
* Called when a held authenticated connection closes.
100+
*
101+
* The only thing this end can say about a cancellation: the client that had
102+
* authenticated and was waiting is gone. Nonsecret and argument-free — it
103+
* reports that the transport ended, never what was on it — and it is what
104+
* lets a suite place the transport's end in the same sequence as the
105+
* authentication cleanup that must follow it.
106+
*/
107+
readonly closed?: () => void;
98108
}
99109

100110
/** Where Git keeps `git-http-backend`, asked of Git rather than guessed. */
@@ -299,7 +309,9 @@ export function useGitHttpRemote(options: GitHttpOptions): Operation<GitHttpRemo
299309
}
300310
if (options.hold?.(requests[requests.length - 1] as ServedGitRequest) === true) {
301311
// Accepted, and then nothing. The socket stays open, so the client is
302-
// waiting on this end rather than on a refusal.
312+
// waiting on this end rather than on a refusal — and when it goes, this
313+
// is where that is observed.
314+
incoming.socket.on("close", () => options.closed?.());
303315
incoming.resume();
304316
return;
305317
}

0 commit comments

Comments
 (0)