refactor(opencode): roll out serviceUse proxy across 14 services + tests (#28576)

This commit is contained in:
Kit Langton
2026-05-20 23:36:27 -04:00
committed by GitHub
parent 69eee26f30
commit 39ea816a72
48 changed files with 640 additions and 622 deletions

View File

@@ -18,14 +18,14 @@ const it = testEffect(Layer.merge(AccountRepo.layer, truncate))
it.live("list returns empty when no accounts exist", () =>
Effect.gen(function* () {
const accounts = yield* AccountRepo.Service.use((r) => r.list())
const accounts = yield* AccountRepo.use.list()
expect(accounts).toEqual([])
}),
)
it.live("active returns none when no accounts exist", () =>
Effect.gen(function* () {
const active = yield* AccountRepo.Service.use((r) => r.active())
const active = yield* AccountRepo.use.active()
expect(Option.isNone(active)).toBe(true)
}),
)
@@ -45,13 +45,13 @@ it.live("persistAccount inserts and getRow retrieves", () =>
}),
)
const row = yield* AccountRepo.Service.use((r) => r.getRow(id))
const row = yield* AccountRepo.use.getRow(id)
expect(Option.isSome(row)).toBe(true)
const value = Option.getOrThrow(row)
expect(value.id).toBe(AccountID.make("user-1"))
expect(value.email).toBe("test@example.com")
const active = yield* AccountRepo.Service.use((r) => r.active())
const active = yield* AccountRepo.use.active()
expect(Option.getOrThrow(active).active_org_id).toBe(OrgID.make("org-1"))
}),
)
@@ -72,9 +72,9 @@ it.live("persistAccount normalizes trailing slashes in stored server URLs", () =
}),
)
const row = yield* AccountRepo.Service.use((r) => r.getRow(id))
const active = yield* AccountRepo.Service.use((r) => r.active())
const list = yield* AccountRepo.Service.use((r) => r.list())
const row = yield* AccountRepo.use.getRow(id)
const active = yield* AccountRepo.use.active()
const list = yield* AccountRepo.use.list()
expect(Option.getOrThrow(row).url).toBe("https://control.example.com")
expect(Option.getOrThrow(active).url).toBe("https://control.example.com")
@@ -112,7 +112,7 @@ it.live("persistAccount sets the active account and org", () =>
)
// Last persisted account is active with its org
const active = yield* AccountRepo.Service.use((r) => r.active())
const active = yield* AccountRepo.use.active()
expect(Option.isSome(active)).toBe(true)
expect(Option.getOrThrow(active).id).toBe(AccountID.make("user-2"))
expect(Option.getOrThrow(active).active_org_id).toBe(OrgID.make("org-2"))
@@ -148,7 +148,7 @@ it.live("list returns all accounts", () =>
}),
)
const accounts = yield* AccountRepo.Service.use((r) => r.list())
const accounts = yield* AccountRepo.use.list()
expect(accounts.length).toBe(2)
expect(accounts.map((a) => a.email).sort()).toEqual(["a@example.com", "b@example.com"])
}),
@@ -170,9 +170,9 @@ it.live("remove deletes an account", () =>
}),
)
yield* AccountRepo.Service.use((r) => r.remove(id))
yield* AccountRepo.use.remove(id)
const row = yield* AccountRepo.Service.use((r) => r.getRow(id))
const row = yield* AccountRepo.use.getRow(id)
expect(Option.isNone(row)).toBe(true)
}),
)
@@ -207,12 +207,12 @@ it.live("use stores the selected org and marks the account active", () =>
)
yield* AccountRepo.Service.use((r) => r.use(id1, Option.some(OrgID.make("org-99"))))
const active1 = yield* AccountRepo.Service.use((r) => r.active())
const active1 = yield* AccountRepo.use.active()
expect(Option.getOrThrow(active1).id).toBe(id1)
expect(Option.getOrThrow(active1).active_org_id).toBe(OrgID.make("org-99"))
yield* AccountRepo.Service.use((r) => r.use(id1, Option.none()))
const active2 = yield* AccountRepo.Service.use((r) => r.active())
const active2 = yield* AccountRepo.use.active()
expect(Option.getOrThrow(active2).active_org_id).toBeNull()
}),
)
@@ -243,7 +243,7 @@ it.live("persistToken updates token fields", () =>
}),
)
const row = yield* AccountRepo.Service.use((r) => r.getRow(id))
const row = yield* AccountRepo.use.getRow(id)
const value = Option.getOrThrow(row)
expect(value.access_token).toBe(AccessToken.make("new_token"))
expect(value.refresh_token).toBe(RefreshToken.make("new_refresh"))
@@ -276,7 +276,7 @@ it.live("persistToken with no expiry sets token_expiry to null", () =>
}),
)
const row = yield* AccountRepo.Service.use((r) => r.getRow(id))
const row = yield* AccountRepo.use.getRow(id)
expect(Option.getOrThrow(row).token_expiry).toBeNull()
}),
)
@@ -309,14 +309,14 @@ it.live("persistAccount upserts on conflict", () =>
}),
)
const accounts = yield* AccountRepo.Service.use((r) => r.list())
const accounts = yield* AccountRepo.use.list()
expect(accounts.length).toBe(1)
const row = yield* AccountRepo.Service.use((r) => r.getRow(id))
const row = yield* AccountRepo.use.getRow(id)
const value = Option.getOrThrow(row)
expect(value.access_token).toBe(AccessToken.make("at_v2"))
const active = yield* AccountRepo.Service.use((r) => r.active())
const active = yield* AccountRepo.use.active()
expect(Option.getOrThrow(active).active_org_id).toBe(OrgID.make("org-2"))
}),
)
@@ -337,9 +337,9 @@ it.live("remove clears active state when deleting the active account", () =>
}),
)
yield* AccountRepo.Service.use((r) => r.remove(id))
yield* AccountRepo.use.remove(id)
const active = yield* AccountRepo.Service.use((r) => r.active())
const active = yield* AccountRepo.use.active()
expect(Option.isNone(active)).toBe(true)
}),
)

View File

@@ -88,7 +88,7 @@ it.live("login normalizes trailing slashes in the provided server URL", () =>
}),
)
const result = yield* Account.Service.use((s) => s.login("https://one.example.com/")).pipe(
const result = yield* Account.use.login("https://one.example.com/").pipe(
Effect.provide(live(client)),
)
@@ -109,7 +109,7 @@ it.live("login maps transport failures to account transport errors", () =>
)
const error = yield* Effect.flip(
Account.Service.use((s) => s.login("https://one.example.com")).pipe(Effect.provide(live(client))),
Account.use.login("https://one.example.com").pipe(Effect.provide(live(client))),
)
expect(error).toBeInstanceOf(AccountTransportError)
@@ -163,7 +163,7 @@ it.live("orgsByAccount groups orgs per account", () =>
}),
)
const rows = yield* Account.Service.use((s) => s.orgsByAccount()).pipe(Effect.provide(live(client)))
const rows = yield* Account.use.orgsByAccount().pipe(Effect.provide(live(client)))
expect(rows.map((row) => [row.account.id, row.orgs.map((org) => org.id)]).map(([id, orgs]) => [id, orgs])).toEqual([
[AccountID.make("user-1"), [OrgID.make("org-1")]],
@@ -201,12 +201,12 @@ it.live("token refresh persists the new token", () =>
),
)
const token = yield* Account.Service.use((s) => s.token(id)).pipe(Effect.provide(live(client)))
const token = yield* Account.use.token(id).pipe(Effect.provide(live(client)))
expect(Option.getOrThrow(token)).toBeDefined()
expect(String(Option.getOrThrow(token))).toBe("at_new")
const row = yield* AccountRepo.Service.use((r) => r.getRow(id))
const row = yield* AccountRepo.use.getRow(id)
const value = Option.getOrThrow(row)
expect(value.access_token).toBe(AccessToken.make("at_new"))
expect(value.refresh_token).toBe(RefreshToken.make("rt_new"))
@@ -246,12 +246,12 @@ it.live("token refreshes before expiry when inside the eager refresh window", ()
}),
)
const token = yield* Account.Service.use((s) => s.token(id)).pipe(Effect.provide(live(client)))
const token = yield* Account.use.token(id).pipe(Effect.provide(live(client)))
expect(String(Option.getOrThrow(token))).toBe("at_new")
expect(refreshCalls).toBe(1)
const row = yield* AccountRepo.Service.use((r) => r.getRow(id))
const row = yield* AccountRepo.use.getRow(id)
const value = Option.getOrThrow(row)
expect(value.access_token).toBe(AccessToken.make("at_new"))
expect(value.refresh_token).toBe(RefreshToken.make("rt_new"))
@@ -315,7 +315,7 @@ it.live("concurrent config and token requests coalesce token refresh", () =>
expect(String(Option.getOrThrow(token))).toBe("at_new")
expect(refreshCalls).toBe(1)
const row = yield* AccountRepo.Service.use((r) => r.getRow(id))
const row = yield* AccountRepo.use.getRow(id)
const value = Option.getOrThrow(row)
expect(value.access_token).toBe(AccessToken.make("at_new"))
expect(value.refresh_token).toBe(RefreshToken.make("rt_new"))
@@ -388,7 +388,7 @@ it.live("poll stores the account and first org on success", () =>
expect(res.email).toBe("user@example.com")
}
const active = yield* AccountRepo.Service.use((r) => r.active())
const active = yield* AccountRepo.use.active()
expect(Option.getOrThrow(active)).toEqual(
expect.objectContaining({
id: "user-1",