Repository navigation
feat(worker): harness composition, D1/KV/R2 bindings, core table migrations and wrangler.toml (#15) - #67
Merged
Conversation
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves the code part of #15. The owner steps (create the Cloudflare resources, set the secrets, deploy staging) are still open; see below.
What changed
crates/tokker-worker/src/lib.rs.db("DB").kv("KV").blob("BUCKET").rate_limiter("RATE_LIMITER").Cloudflareis now built once and cloned. It is#[derive(Clone)], and before this change it was built twice..cors_origins(["https://tokker.dev"]).Harness::build()refuses a venture with no CORS origin (cratefield-core 0.8.0venture.rs:221-223), so the old stub panicked on its first request.#[event(scheduled)]handler that delegates toserve_scheduled. It runs under the runtime's limits of 25 s and 40 subrequests./__health,/__readyand/__surfaceare built intoHarness::router(harness.rs:657-661), so no extra wiring was needed.wrangler.toml(new, at the repo root)[env.staging](workers_dev = true) and[env.production].[[ratelimits]]entry (simple = { limit = 120, period = 60 }).[triggers] crons = ["*/30 * * * *"]is hand-maintained until Cratefield's manifest cron field lands.vars,triggers, bindings,ratelimitsorworkers_devfrom the top level into a named env, so each env declares all of them again.HARNESS_SECRETandADMIN_TOKENappear by name only, withwrangler secret putinstructions.worker-build --release crates/tokker-worker, and it needs a one-timecargo install worker-build.migrations/0001_core_tables.sql(new)providers,models,offers,plans,sourcesandfx. Each hasid TEXT PRIMARY KEY, the columns the API filters on, andjson TEXT NOT NULLholding the full row.docs/SCHEMA.md:creator,open_weights,provider_type,currency,input_per_mtok,usd_blended_3to1,context_window,last_verified_atand others.docs/SCHEMA.md./v1/offersand for/v1/models/{slug}/cheapest(model_id, usd_blended_3to1).Migrations(see the runtime README); a venture ships its SQL through wrangler'smigrations_dir. SoTokkerApi::migrations()staysEMPTY.tools/smoke.mjs(new)SMOKE_URL, from argv, or defaults tohttp://127.0.0.1:8787./__healthanswers 2xx, that/__readyanswers 2xx (which meansSELECT 1through D1 worked), that/__surfaceanswers 2xx with JSON, and that an unknown path answers 404.Verification
cargo fmt --check,cargo clippy -D warnings,cargo test,cargo docwith-D warnings, thewasm32-unknown-unknownbuild oftokker-worker, andcargo tree -d --depth 0 | grep cratefield, which printed nothing.wrangler d1 migrations apply DB --localapplied 0001 (16 commands).wrangler dev --local(wrangler 4.149.0) came up with all five bindings. The smoke checks all passed:/__health200,/__ready200,/__surface200 with JSON, unknown path 404.tools/. The smoke test therefore ran from a copy undertarget/thatcmpconfirmed is byte-identical totools/smoke.mjs.POST /cdn-cgi/local/scheduled?cron=*/30 * * * *answered 200, so the cron handler runs.wrangler deploy --dry-run --env stagingand--env productionboth resolve all bindings. Nothing was uploaded.docs/SCHEMA.mdand found nothing to fix.Look closely at
wrangler.toml: the D1database_ids, the KV ids, and the[[ratelimits]]namespace_ids (1001, 2001 and 3001 for local, staging and production). Eachnamespace_idmust be unique on the Factory0 account./v1/*routes when a named rate limiter binding is missing (runtimelib.rs:207-217). That is why every env declares[[ratelimits]].ENV=productionin[env.production].varsturns on Cratefield's production readiness gate (route_policy.rs:801). It needsHARNESS_SECRET(at least 32 bytes) andADMIN_TOKENset first.wrangleris not a devDependency.package.jsonis being edited by sibling CI checks for data PRs: id stability, sanity bounds, and provenance on every changed value #14, so I left it alone. A follow-up could addwranglerand annpm run smokescript.region_notes, no structured region field, so the compare page's region filter has no column to index yet.sources[]entries have noid, so a loader will have to build one, for example<part>/<provider_id>.Owner steps (needs-human, not done here)
ratelimitsnamespace id. Fill in the ids inwrangler.toml.wrangler secret put HARNESS_SECRET --env stagingandwrangler secret put ADMIN_TOKEN --env staging.wrangler d1 migrations apply DB --env staging --remote, thenwrangler deploy --env staging(workers.dev only).SMOKE_URL=https://<staging>.workers.dev node tools/smoke.mjs.Size and overlap
4 files, about 317 changed lines:
lib.rs+37/−6,wrangler.toml120 lines, the migration 107 lines,smoke.mjs66 lines. This adds the repo's first rootwrangler.tomland firstmigrations/directory. Sibling #12 (the FX policy work) may also want anfxtable; this PR already creates one, keyed on currency, withrate.Closes #15
🤖 Generated by Colonizer in a microVM
Co-Authored-By: Colonizer Settlers 331648616+colonizer-settlers@users.noreply.github.com