@@ -446,128 +446,137 @@ it.layer(layerCodexTextGenerationTest)("CodexTextGeneration", (it) => {
446446 );
447447});
448448
449- it.effect.each(["usage-error", "preflight", "ordinary-error", "retry-fails"] as const)(
450- "text generation fallback: %s",
451- (scenario) =>
452- Effect.gen(function* () {
453- const primary = ProviderInstanceId.make("codex");
454- const preferred = ProviderInstanceId.make("claude_work");
455- const calls: string[] = [];
456- const snapshots: ServerProvider[] = [
457- {
458- instanceId: primary,
459- driver: ProviderDriverKind.make("codex"),
460- enabled: true,
461- installed: true,
462- status: "ready",
463- auth: { status: "authenticated" },
464- version: null,
465- checkedAt: "1970-01-01T00:00:00Z",
466- models: [],
467- slashCommands: [],
468- skills: [],
469- ...(scenario === "preflight"
470- ? {
471- usageLimits: {
472- checkedAt: "1970-01-01T00:00:00Z",
473- windows: [{ id: "session", kind: "session", label: "Session", usedPercent: 100 }],
474- },
475- }
476- : {}),
477- },
478- {
479- instanceId: preferred,
480- driver: ProviderDriverKind.make("claudeAgent"),
481- enabled: true,
482- installed: true,
483- status: "ready",
484- auth: { status: "authenticated" },
485- version: null,
486- checkedAt: "1970-01-01T00:00:00Z",
487- models: [],
488- slashCommands: [],
489- skills: [],
490- },
491- ];
492- const instances: ProviderInstance[] = snapshots.map((snapshot) => ({
493- instanceId: snapshot.instanceId,
494- driverKind: snapshot.driver,
495- continuationIdentity: { driverKind: snapshot.driver, continuationKey: snapshot.instanceId },
496- displayName: undefined,
449+ it.effect.each([
450+ "usage-error",
451+ "typed-quota",
452+ "preflight",
453+ "ordinary-error",
454+ "retry-fails",
455+ ] as const)("text generation fallback: %s", (scenario) =>
456+ Effect.gen(function* () {
457+ const primary = ProviderInstanceId.make("codex");
458+ const preferred = ProviderInstanceId.make("claude_work");
459+ const calls: string[] = [];
460+ const snapshots: ServerProvider[] = [
461+ {
462+ instanceId: primary,
463+ driver: ProviderDriverKind.make("codex"),
497464 enabled: true,
498- snapshot: { getSnapshot: Effect.succeed(snapshot) } as ProviderInstance["snapshot"],
499- orchestrationAdapter: {} as ProviderInstance["orchestrationAdapter"],
500- textGeneration: TextGeneration.TextGeneration.of({
501- generateCommitMessage: () => Effect.die("unused"),
502- generatePrContent: () => Effect.die("unused"),
503- generateBranchName: () => Effect.die("unused"),
504- generateReviewGuide: () => Effect.die("unused"),
505- generateThreadTitle: (input) =>
506- Effect.gen(function* () {
507- calls.push(input.modelSelection.instanceId);
508- if (snapshot.instanceId === primary || scenario === "retry-fails")
509- return yield* new TextGenerationError({
510- operation: "generateThreadTitle",
511- detail:
512- scenario === "ordinary-error"
513- ? "invalid credentials"
465+ installed: true,
466+ status: "ready",
467+ auth: { status: "authenticated" },
468+ version: null,
469+ checkedAt: "1970-01-01T00:00:00Z",
470+ models: [],
471+ slashCommands: [],
472+ skills: [],
473+ ...(scenario === "preflight"
474+ ? {
475+ usageLimits: {
476+ checkedAt: "1970-01-01T00:00:00Z",
477+ windows: [{ id: "session", kind: "session", label: "Session", usedPercent: 100 }],
478+ },
479+ }
480+ : {}),
481+ },
482+ {
483+ instanceId: preferred,
484+ driver: ProviderDriverKind.make("claudeAgent"),
485+ enabled: true,
486+ installed: true,
487+ status: "ready",
488+ auth: { status: "authenticated" },
489+ version: null,
490+ checkedAt: "1970-01-01T00:00:00Z",
491+ models: [],
492+ slashCommands: [],
493+ skills: [],
494+ },
495+ ];
496+ const instances: ProviderInstance[] = snapshots.map((snapshot) => ({
497+ instanceId: snapshot.instanceId,
498+ driverKind: snapshot.driver,
499+ continuationIdentity: { driverKind: snapshot.driver, continuationKey: snapshot.instanceId },
500+ displayName: undefined,
501+ enabled: true,
502+ snapshot: { getSnapshot: Effect.succeed(snapshot) } as ProviderInstance["snapshot"],
503+ orchestrationAdapter: {} as ProviderInstance["orchestrationAdapter"],
504+ textGeneration: TextGeneration.TextGeneration.of({
505+ generateCommitMessage: () => Effect.die("unused"),
506+ generatePrContent: () => Effect.die("unused"),
507+ generateBranchName: () => Effect.die("unused"),
508+ generateReviewGuide: () => Effect.die("unused"),
509+ generateThreadTitle: (input) =>
510+ Effect.gen(function* () {
511+ calls.push(input.modelSelection.instanceId);
512+ if (snapshot.instanceId === primary || scenario === "retry-fails")
513+ return yield* new TextGenerationError({
514+ operation: "generateThreadTitle",
515+ detail:
516+ scenario === "ordinary-error"
517+ ? "invalid credentials"
518+ : scenario === "typed-quota"
519+ ? "Provider request failed"
514520 : "You've hit your usage limit",
515- });
516- expect(input.modelSelection.model).toBe(
517- DEFAULT_TEXT_GENERATION_MODEL_BY_PROVIDER[ProviderDriverKind.make("claudeAgent")],
518- );
519- expect(input.modelSelection.options).toBeUndefined();
520- return { title: "Fallback title" };
521- }),
522- }),
523- }));
524- const service = yield* TextGeneration.make.pipe(
525- Effect.provide(
526- Layer.mergeAll(
527- Layer.mock(ProviderInstanceRegistry.ProviderInstanceRegistry)({
528- listInstances: Effect.succeed(instances),
529- getInstance: (id) =>
530- Effect.succeed(instances.find((instance) => instance.instanceId === id)),
531- }),
532- Layer.mock(ProviderRegistry.ProviderRegistry)({
533- getProviders: Effect.succeed(snapshots),
534- }),
535- Layer.mock(ServerSettings.ServerSettingsService)({
536- getSettings: Effect.succeed({
537- ...DEFAULT_SERVER_SETTINGS,
538- fallbackModelSelection: { instanceId: preferred, model: "chat-model" },
539- providerInstances: {
540- [preferred]: { driver: ProviderDriverKind.make("claudeAgent"), config: {} },
541- },
542- }),
543- }),
544- Layer.mock(SourceControlProviderRegistry.SourceControlProviderRegistry)({
545- resolveLink: () => Effect.die("unused"),
521+ ...(scenario === "typed-quota" && snapshot.instanceId === primary
522+ ? { cause: { type: "provider.quota", message: "Budget exceeded", status: 429 } }
523+ : {}),
524+ });
525+ expect(input.modelSelection.model).toBe(
526+ DEFAULT_TEXT_GENERATION_MODEL_BY_PROVIDER[ProviderDriverKind.make("claudeAgent")],
527+ );
528+ expect(input.modelSelection.options).toBeUndefined();
529+ return { title: "Fallback title" };
530+ }),
531+ }),
532+ }));
533+ const service = yield* TextGeneration.make.pipe(
534+ Effect.provide(
535+ Layer.mergeAll(
536+ Layer.mock(ProviderInstanceRegistry.ProviderInstanceRegistry)({
537+ listInstances: Effect.succeed(instances),
538+ getInstance: (id) =>
539+ Effect.succeed(instances.find((instance) => instance.instanceId === id)),
540+ }),
541+ Layer.mock(ProviderRegistry.ProviderRegistry)({
542+ getProviders: Effect.succeed(snapshots),
543+ }),
544+ Layer.mock(ServerSettings.ServerSettingsService)({
545+ getSettings: Effect.succeed({
546+ ...DEFAULT_SERVER_SETTINGS,
547+ fallbackModelSelection: { instanceId: preferred, model: "chat-model" },
548+ providerInstances: {
549+ [preferred]: { driver: ProviderDriverKind.make("claudeAgent"), config: {} },
550+ },
546551 }),
547- ),
552+ }),
553+ Layer.mock(SourceControlProviderRegistry.SourceControlProviderRegistry)({
554+ resolveLink: () => Effect.die("unused"),
555+ }),
548556 ),
549- );
550- const result = yield* service
551- .generateThreadTitle({
552- cwd: "/tmp",
553- message: "hello",
554- linkedContext: "",
555- modelSelection: {
556- instanceId: primary,
557- model: "chat-model",
558- options: [{ id: "effort", value: "high" }],
559- },
560- })
561- .pipe(Effect.result);
562- expect(calls).toEqual(
563- scenario === "preflight"
564- ? [preferred]
565- : scenario === "ordinary-error"
566- ? [primary]
567- : [primary, preferred],
568- );
569- expect(result._tag).toBe(
570- scenario === "ordinary-error" || scenario === "retry-fails" ? "Failure" : "Success",
571- );
572- }),
557+ ),
558+ );
559+ const result = yield* service
560+ .generateThreadTitle({
561+ cwd: "/tmp",
562+ message: "hello",
563+ linkedContext: "",
564+ modelSelection: {
565+ instanceId: primary,
566+ model: "chat-model",
567+ options: [{ id: "effort", value: "high" }],
568+ },
569+ })
570+ .pipe(Effect.result);
571+ expect(calls).toEqual(
572+ scenario === "preflight"
573+ ? [preferred]
574+ : scenario === "ordinary-error"
575+ ? [primary]
576+ : [primary, preferred],
577+ );
578+ expect(result._tag).toBe(
579+ scenario === "ordinary-error" || scenario === "retry-fails" ? "Failure" : "Success",
580+ );
581+ }),
573582);
0 commit comments