Skip to content

Commit 9b2c73b

Browse files
Discard changes to apps/server/src/sourceControl/SourceControlDiscovery.test.ts
1 parent 5bb967c commit 9b2c73b

1 file changed

Lines changed: 1 addition & 143 deletions

File tree

‎apps/server/src/sourceControl/SourceControlDiscovery.test.ts‎

Lines changed: 1 addition & 143 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as Effect from "effect/Effect";
44
import * as Layer from "effect/Layer";
55
import * as Option from "effect/Option";
66
import { ChildProcessSpawner } from "effect/unstable/process";
7-
import { VcsProcessSpawnError, VcsProcessTimeoutError } from "@t3tools/contracts";
7+
import { VcsProcessSpawnError } from "@t3tools/contracts";
88

99
import * as ServerConfig from "../config.ts";
1010
import * as VcsDriverRegistry from "../vcs/VcsDriverRegistry.ts";
@@ -281,145 +281,3 @@ Logged in to gitlab.com as gitlab-user
281281
);
282282
}).pipe(Effect.provide(testLayer));
283283
});
284-
285-
it.effect(
286-
"keeps a slow provider CLI available when its probe budget covers the startup cost",
287-
() => {
288-
// `az` boots a fresh Python interpreter on every invocation, so `az --version` takes
289-
// roughly six seconds on Windows. This mock answers only when the caller waits that long.
290-
const azStartupMs = 6_000;
291-
const processMock = {
292-
run: (input: VcsProcess.VcsProcessInput) => {
293-
if (input.command === "az") {
294-
if ((input.timeoutMs ?? 0) < azStartupMs) {
295-
return Effect.fail(
296-
new VcsProcessTimeoutError({
297-
operation: input.operation,
298-
command: input.command,
299-
cwd: input.cwd,
300-
timeoutMs: input.timeoutMs ?? 0,
301-
}),
302-
);
303-
}
304-
if (input.args[0] === "--version") {
305-
return Effect.succeed(processOutput("azure-cli 2.77.0\n"));
306-
}
307-
if (input.args.join(" ") === "account show --query user.name -o tsv") {
308-
return Effect.succeed(processOutput("[email protected]\n"));
309-
}
310-
}
311-
return Effect.fail(
312-
new VcsProcessSpawnError({
313-
operation: input.operation,
314-
command: input.command,
315-
cwd: input.cwd,
316-
cause: new Error(`${input.command} not found`),
317-
}),
318-
);
319-
},
320-
} satisfies Partial<VcsProcess.VcsProcess["Service"]>;
321-
const testLayer = SourceControlDiscovery.layer.pipe(
322-
Layer.provide(
323-
ServerConfig.layerTest(process.cwd(), {
324-
prefix: "t3-source-control-slow-cli-discovery-",
325-
}),
326-
),
327-
Layer.provide(Layer.mock(VcsProcess.VcsProcess)(processMock)),
328-
Layer.provide(
329-
sourceControlProviderRegistryTestLayer({
330-
process: processMock,
331-
bitbucket: {
332-
probeAuth: Effect.succeed({
333-
status: "unauthenticated",
334-
account: Option.none(),
335-
host: Option.some("bitbucket.org"),
336-
detail: Option.none(),
337-
}),
338-
},
339-
}),
340-
),
341-
Layer.provideMerge(NodeServices.layer),
342-
);
343-
344-
return Effect.gen(function* () {
345-
const discovery = yield* SourceControlDiscovery.SourceControlDiscovery;
346-
const result = yield* discovery.discover;
347-
348-
const azure = result.sourceControlProviders.find((item) => item.kind === "azure-devops");
349-
assert.ok(azure);
350-
assert.strictEqual(azure.status, "available");
351-
assert.strictEqual(azure.auth.status, "authenticated");
352-
assert.deepStrictEqual(azure.auth.account, Option.some("[email protected]"));
353-
}).pipe(Effect.provide(testLayer));
354-
},
355-
);
356-
357-
it.effect(
358-
"spends the raised budget twice when a slow CLI answers --version but wedges on auth",
359-
() => {
360-
// The version and auth probes are sequential and share one per-spec budget, so raising
361-
// it also raises the worst case: an `az` that is installed but wedged on `account show`
362-
// costs the budget twice before discovery reports an unknown auth state. This test pins
363-
// that cost so it stays visible if the number is ever changed.
364-
const budgets: Array<number> = [];
365-
const processMock = {
366-
run: (input: VcsProcess.VcsProcessInput) => {
367-
if (input.command === "az") {
368-
budgets.push(input.timeoutMs ?? 0);
369-
if (input.args[0] === "--version") {
370-
return Effect.succeed(processOutput("azure-cli 2.77.0\n"));
371-
}
372-
return Effect.fail(
373-
new VcsProcessTimeoutError({
374-
operation: input.operation,
375-
command: input.command,
376-
cwd: input.cwd,
377-
timeoutMs: input.timeoutMs ?? 0,
378-
}),
379-
);
380-
}
381-
return Effect.fail(
382-
new VcsProcessSpawnError({
383-
operation: input.operation,
384-
command: input.command,
385-
cwd: input.cwd,
386-
cause: new Error(`${input.command} not found`),
387-
}),
388-
);
389-
},
390-
} satisfies Partial<VcsProcess.VcsProcess["Service"]>;
391-
const testLayer = SourceControlDiscovery.layer.pipe(
392-
Layer.provide(
393-
ServerConfig.layerTest(process.cwd(), {
394-
prefix: "t3-source-control-wedged-cli-discovery-",
395-
}),
396-
),
397-
Layer.provide(Layer.mock(VcsProcess.VcsProcess)(processMock)),
398-
Layer.provide(
399-
sourceControlProviderRegistryTestLayer({
400-
process: processMock,
401-
bitbucket: {
402-
probeAuth: Effect.succeed({
403-
status: "unauthenticated",
404-
account: Option.none(),
405-
host: Option.some("bitbucket.org"),
406-
detail: Option.none(),
407-
}),
408-
},
409-
}),
410-
),
411-
Layer.provideMerge(NodeServices.layer),
412-
);
413-
414-
return Effect.gen(function* () {
415-
const discovery = yield* SourceControlDiscovery.SourceControlDiscovery;
416-
const result = yield* discovery.discover;
417-
418-
const azure = result.sourceControlProviders.find((item) => item.kind === "azure-devops");
419-
assert.ok(azure);
420-
assert.strictEqual(azure.status, "available");
421-
assert.strictEqual(azure.auth.status, "unknown");
422-
assert.deepStrictEqual(budgets, [20_000, 20_000]);
423-
}).pipe(Effect.provide(testLayer));
424-
},
425-
);

0 commit comments

Comments
 (0)