Skip to content

refactor(bot): extract pkg/bot store from cmd (#326d) - #344

Merged
scttfrdmn merged 1 commit into
mainfrom
audit/326d-bot-store
Jul 12, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
audit/326d-bot-store

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Closes #326 (store-layer extraction, audit #328). Fourth and final domain PR. No behavior change; wire format preserved and asserted.

What changed

cmd/bot.go talked to DynamoDB directly across ~14 ops (register/deregister/enable/disable/list, the workspace add/remove/list/destroy verbs, and the lookupSlackUserByEmail/redeemConnectCode helpers), with three item structs in cmd/. Added pkg/bot (Client mirroring pkg/alerts.Client; NewClientWithTableNames honors the --table/--registry-table/--workspaces-table overrides) holding Registration/Workspace/ConnectCode and:

  • registry: UpsertRegistration (preserves enabled + created_at via if_not_exists), DeleteRegistration, SetRegistrationEnabled (keeps attribute_exists guard), ListRegistrationsByWorkspace (prefix scan), BatchDeleteRegistrations (25-chunk BatchWriteItem).
  • workspaces: PutWorkspace, DeleteWorkspace, GetWorkspace, ListWorkspaces, UpdateWorkspaceTokens.
  • connect codes: RedeemConnectCode (DeleteItem ReturnValues=ALL_OLD; the TTL-expiry check stays in cmd to preserve exact behavior).

A botClient(cfg) cmd helper threads the flag overrides through. All ConditionExpression/if_not_exists/ReturnValues/chunking semantics preserved verbatim.

Wire format preserved

The dynamodbav tags moved byte-identical (diff vs main confirms) — the separate spore-bot Lambda repo (authoritative writer) and dashboard-api share the format. Table names unchanged (env-resolved spore-bot-registry / spore-bot-workspaces).

Verification

  • go build ./..., go vet ./cmd ./pkg/bot, gofmt clean.
  • New pkg/bot/bot_substrate_test.go passes: registration lifecycle incl. enabled-preservation on re-upsert; 30-item batch delete across chunks; workspace CRUD + token update; connect-code redeem with SPORE- prefix + single-use. (Note: the attribute_exists guard fails only against real DynamoDB — the Substrate emulator doesn't enforce conditions — so that negative path isn't asserted; called out in a test comment.)
  • go test ./cmd green (excl. pre-existing TestCatalogValid / feat(plugin): permissions declaration block (#388) #392).
  • Rebuilt bin/spawn; recursive command+flag tree byte-identical vs main.

With this, all 5 cmd files (bot/team/pipeline/list-sweeps/collect) are off raw DynamoDB → #327 (a guardrail test forbidding new aws-sdk imports in cmd/) is now feasible.

Fourth and final store-layer extraction (#326). cmd/bot.go talked to
DynamoDB directly across ~14 ops in register/deregister/enable/disable/
list, the workspace add/remove/list/destroy verbs, and the lookupSlack /
redeemConnectCode helpers, with three item structs in cmd/. Added pkg/bot
(Client mirrors pkg/alerts.Client; NewClientWithTableNames honors the
--table/--workspaces-table flag overrides) holding Registration/Workspace/
ConnectCode and the domain methods:
- registry: UpsertRegistration (preserves enabled + created_at via
  if_not_exists), DeleteRegistration, SetRegistrationEnabled (keeps the
  attribute_exists guard), ListRegistrationsByWorkspace (prefix scan),
  BatchDeleteRegistrations (25-chunk BatchWriteItem)
- workspaces: PutWorkspace, DeleteWorkspace, GetWorkspace, ListWorkspaces,
  UpdateWorkspaceTokens
- connect codes: RedeemConnectCode (DeleteItem ReturnValues ALL_OLD; the
  TTL-expiry check stays in cmd to preserve exact behavior)

A botClient(cfg) cmd helper threads the flag overrides. lookupSlack/
redeem dropped their unused table-override param (botClient reads the
globals). All ConditionExpression / if_not_exists / ReturnValues / chunking
semantics preserved verbatim.

Wire format preserved: dynamodbav tags moved byte-identical (diff vs main
confirms) — the separate spore-bot Lambda repo and dashboard-api share them.
Table names unchanged (env-resolved spore-bot-registry / -workspaces).

Verified: go build ./..., go vet, gofmt clean; new pkg/bot substrate tests
(registration lifecycle incl. enabled-preservation on re-upsert; 30-item
batch delete across chunks; workspace CRUD + token update; connect-code
redeem w/ SPORE- prefix + single-use); cmd tests green; tree byte-identical.
@codecov

codecov Bot commented Jul 12, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 58.14815% with 113 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cmd/bot.go 0.00% 59 Missing ⚠️
pkg/bot/bot.go 74.40% 37 Missing and 17 partials ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit 8dae8ab into main Jul 12, 2026
7 checks passed
@scttfrdmn
scttfrdmn deleted the audit/326d-bot-store branch July 12, 2026 03:03
scttfrdmn added a commit that referenced this pull request Jul 22, 2026
#433)

* feat(status): show a Lifecycle protection summary (#429-review)

Fourth external-review polish: surface the safety model in the CLI, not just
the docs. `spawn status` on a running managed instance now appends:

  Lifecycle protection:
    In-instance (spored):  enforces TTL + idle rules on the instance itself
    Out-of-band reaper:    backstop in the spore.host-infra account, if deployed
    Termination deadline:  2026-07-22 18:00 PDT (in 2h 55m)
    Max compute cost:      ~$4.82 by deadline (on-demand rate, compute only; ...)
    Idle timeout:          30m (stops the instance when idle; never terminates)

Computed controller-side from tags: deadline from the launch-anchored
spawn:ttl-deadline tag (falls back to launch+TTL), max cost from
LookupEC2OnDemandPrice x hours-to-deadline. Honest about the reaper — it is
NOT authoritatively visible from the launch account (pkg/doctor ReaperConfigured
says the same), so it is described as a backstop 'if deployed' rather than
claiming dual enforcement. Shown for both the SSH and SSM status paths; only for
running/pending managed instances. Unit-tested (block presence, gating,
deadline resolution).

* security: sign CLI release artifacts with keyless cosign + SLSA (#430)

Signs checksums.txt with keyless cosign (Sigstore, GitHub OIDC identity) and
adds SLSA build provenance for the downloadable spawn CLI artifacts. Separate
from and complementary to spored's KMS publisher-signing + boot verification
(#440) — the spored S3-upload step is untouched.

- .goreleaser.yaml: signs: block → cosign sign-blob --bundle over checksums.txt
  (cosign 3.x bundle format). Publishes checksums.txt.bundle.
- release.yaml: install cosign, add attestations: write, add
  attest-build-provenance over checksums.txt. id-token: write already present.

Takes effect from the next tagged release. Refs #344. Closes #430
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[audit] Structural (design): cmd/ talks to DynamoDB directly (27 sites, ~5 files) — extract a store/repository layer

1 participant