Skip to content

Commit 54f9e3f

Browse files
mayoalexanderclaude
andcommitted
fix(programs): --price 0 was dropped, and the bloq guard 404'd every real bloq
Two follow-ups to the envelope fix, both caught by running the commands rather than reading them: - package-create used `if (args.price)`, so a deliberate `--price 0` was omitted from the payload and the API's `required` rule rejected the call. A FREE tier was impossible to create, and the error pointed at a field the user had in fact supplied. Same for --trial-days. max_members stays falsy-dropped on purpose: its rule is `nullable|integer|min:1`, so 0 ("unlimited") must be omitted rather than sent. - bloqExists() called /api/v1/bloqs/{id}, which does not exist. It 404s for every bloq, so the new dangling-reference guard refused writes for bloqs that were perfectly real — caught on #314, which `iris bloqs get` resolves fine. Bloqs are USER-SCOPED: /api/v1/user/{userId}/bloqs/{id}. A guard that cannot tell "absent" from "I looked in the wrong place" is worse than no guard, so it now fails OPEN on an unverifiable lookup (no user id, network error) and only blocks on a definite 404. Verified: guard accepts bloq 314, rejects 609 and 999999; `--price 0` creates. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01A4EaJxjqBiMsZtgJuvgXxp
1 parent 966113b commit 54f9e3f

1 file changed

Lines changed: 15 additions & 6 deletions

File tree

‎packages/opencode/src/cli/cmd/platform-programs.ts‎

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { cmd } from "./cmd"
22
import * as prompts from "./clack"
33
import { UI } from "../ui"
4-
import { irisFetch, requireAuth, handleApiError, printDivider, printKV, dim, bold, success, highlight, isNonInteractive } from "./iris-api"
4+
import { irisFetch, requireAuth, handleApiError, printDivider, printKV, dim, bold, success, highlight, isNonInteractive, resolveUserId } from "./iris-api"
55
import { existsSync, mkdirSync, writeFileSync, readFileSync } from "fs"
66
import { join, basename } from "path"
77

@@ -64,13 +64,18 @@ function readLocalProgram(filepath: string): any {
6464
// cannot read as healthy afterwards.
6565
async function bloqExists(bloqId: number | string): Promise<boolean> {
6666
try {
67-
const res = await irisFetch(`/api/v1/bloqs/${bloqId}`)
67+
// Bloqs are USER-SCOPED. An earlier version of this guard called
68+
// /api/v1/bloqs/{id}, which does not exist — it 404s for every bloq, so the
69+
// guard refused writes for bloqs that were perfectly real. Caught on #314.
70+
const userId = await resolveUserId()
71+
if (!userId) return true // cannot verify → do not block the write
72+
const res = await irisFetch(`/api/v1/user/${userId}/bloqs/${bloqId}`)
6873
if (!res.ok) return false
6974
const json = (await res.json()) as any
7075
const b = json?.data ?? json
71-
return Boolean((b?.bloq ?? b)?.id)
76+
return Boolean(b?.id ?? b?.name)
7277
} catch {
73-
return false
78+
return true // network/parse failure is not evidence of absence
7479
}
7580
}
7681

@@ -685,10 +690,14 @@ const PackageCreateCommand = cmd({
685690

686691
try {
687692
const payload: Record<string, unknown> = { name, billing_interval: args.interval, is_active: true }
688-
if (args.price) payload.price = args.price
693+
// `if (args.price)` dropped a deliberate 0, so the API's `required` rule
694+
// rejected the call and a FREE tier was impossible to create. Same for
695+
// trial-days. max_members stays falsy-dropped on purpose: the API rule is
696+
// `nullable|integer|min:1`, so 0 ("unlimited") must be omitted, not sent.
697+
if (args.price !== undefined) payload.price = args.price
689698
if (args.description) payload.description = args.description
690699
if (args["max-members"]) payload.max_members = args["max-members"]
691-
if (args["trial-days"]) payload.trial_days = args["trial-days"]
700+
if (args["trial-days"] !== undefined) payload.trial_days = args["trial-days"]
692701

693702
const res = await irisFetch(`/api/v1/programs/${args["program-id"]}/packages`, { method: "POST", body: JSON.stringify(payload) })
694703
const ok = await handleApiError(res, "Create package")

0 commit comments

Comments
 (0)