MCPcopy
hub / github.com/coder/mux / setGoal

Function setGoal

src/node/services/workspaceService.test.ts:5959–5982  ·  view source on GitHub ↗
(goal: GoalRecordV1 | null)

Source from the content-addressed store, hash-verified

5957 }
5958
5959 function setGoal(goal: GoalRecordV1 | null): void {
5960 // Mock the canonical WorkspaceGoalService.assertPricedModelForBudgetedGoal
5961 // by composing the same primitives the real implementation uses (model
5962 // pricing + hasBudgetedResumableGoal). This keeps the gate behaviour in
5963 // one place — the test still exercises the WS-side delegation contract.
5964 const fakeGoalService: Pick<
5965 WorkspaceGoalService,
5966 "getGoal" | "assertPricedModelForBudgetedGoal"
5967 > = {
5968 getGoal: mock(() => Promise.resolve(goal)),
5969 assertPricedModelForBudgetedGoal: mock((_workspaceId: string, model?: string) => {
5970 if (!model || modelHasPricingData(model)) {
5971 return Promise.resolve(Ok(undefined));
5972 }
5973 if (!hasBudgetedResumableGoal(goal)) {
5974 return Promise.resolve(Ok(undefined));
5975 }
5976 return Promise.resolve(
5977 Err({ type: "unknown" as const, raw: UNPRICED_TARGET_MODEL_GOAL_MESSAGE })
5978 );
5979 }),
5980 };
5981 workspaceService.setWorkspaceGoalService(fakeGoalService as unknown as WorkspaceGoalService);
5982 }
5983
5984 function callGate(options: GateOptions | undefined): Promise<Result<void, SendMessageError>> {
5985 return (workspaceService as unknown as GateAccess).assertPricedModelForBudgetedGoal(

Callers 1

Calls 6

modelHasPricingDataFunction · 0.90
OkFunction · 0.90
hasBudgetedResumableGoalFunction · 0.90
ErrFunction · 0.90
resolveMethod · 0.80

Tested by

no test coverage detected