chore: remove legacy terminology and dead code
- Reword docs and comments to drop vague "legacy" qualifiers where they no longer describe deprecation status - Remove unused code: RecentEvents, MessageEvent.ToLegacy, index setState, stderr redaction tool, telegramOnlyCommands - Delete or comment out tests covering removed or superseded behavior
This commit is contained in:
1 parent
e10cbbc92c
commit
308666b410
35 files changed
+664
-1399
No files matched your search
@@ -58,7 +58,7 @@ Do not simplify these facts into the target model:
|
||||
| Enforcement | Gates, read-only/protected paths, TDD inverted test gates, and diff caps are represented outside prompt prose. | `internal/agentexec/inprocess.go`; `internal/workflow/{agent,tdd,steps}.go` |
|
||||
| Configuration | `internal/config.Config`, `IdentityConfig`, `Repo`, and task snapshots mix input decoding with runtime concerns. | `internal/config/config.go` |
|
||||
| Identity | Configured names and bot usernames act as process-local identity keys. There is no durable Identity domain. | `internal/daemon/daemon.go`; `internal/store/store.go`; `internal/gateway/session.go` |
|
||||
| Messaging | `internal/gateway` contains both legacy `Message` flow and richer `MessageEvent`; channel routing and task control are mixed with conversational behavior. | `internal/gateway/{gateway,messageevent,tasks}.go`; `internal/channels/` |
|
||||
| Messaging | `internal/gateway` contains both the `Message` struct flow and richer `MessageEvent`; channel routing and task control are mixed with conversational behavior. | `internal/gateway/{gateway,messageevent,tasks}.go`; `internal/channels/` |
|
||||
| Plugins | `plugin.Plugin` exposes only `Name` and `Version`; current loading interprets operator-installed Go files with Yaegi. | `internal/plugin/plugin.go` |
|
||||
| Processes | Agent modes include in-process, subprocess, and NATS. Optional containers add a distinct boundary with known gaps. | `internal/config/config.go`; `cmd/archied/main.go`; `ARCHITECTURE.md` |
|
||||
|
||||
|
||||
@@ -195,8 +195,8 @@ diff cap, notification, and forge host. `TaskConfig.ToConfig` reconstructs
|
||||
only those fields. Forge tokens, provider values, NATS credential references,
|
||||
repos, and infrastructure settings do not enter `TaskConfig`.
|
||||
|
||||
At top-level `[forge]`, prefer `token = {engine = "env", key = "NAME"}`. Legacy
|
||||
`token_env = "NAME"` is converted only when structured reference is empty;
|
||||
At top-level `[forge]`, prefer `token = {engine = "env", key = "NAME"}`. The
|
||||
`token_env = "NAME"` form is converted only when structured reference is empty;
|
||||
structured reference wins when both appear. This compatibility rule exists
|
||||
because an earlier migration silently dropped deployed `token_env` values and
|
||||
crash-looped the daemon. `finalize` does not apply that conversion inside each
|
||||
|
||||
@@ -89,7 +89,7 @@ commit `308c199`, not proof that Yaegi cannot run external commands.
|
||||
| Surface | Subject or resource | Bound/current behavior |
|
||||
|---|---|---|
|
||||
| Task discovery | `archie.task.>` in `ARCHIE_TASKS` | Work-queue retention; daemon durable `archie-daemon`; max deliver 3 |
|
||||
| Legacy agent stage | `archie.agent.<task>.request` | Reply inbox in `X-Archie-Reply`; wall-clock budget or 30m |
|
||||
| Per-stage agent request | `archie.agent.<task>.request` | Reply inbox in `X-Archie-Reply`; wall-clock budget or 30m |
|
||||
| Full task handoff | `archie.taskrun.<task-id>` | Core request/reply; no-responder retry 20s every 250ms |
|
||||
| Store RPC | `archie.store.update`, `.transition` | Client timeout 60s by `cmd/archie-agent/taskrun.go` |
|
||||
| Forge RPC | `archie.forge.*` | Error travels in a JSON envelope |
|
||||
@@ -143,7 +143,7 @@ For environment failures:
|
||||
forwards configured provider key variables.
|
||||
- `SubprocessRunner` forwards default compatibility variables, configured
|
||||
`[agent].env` names, and only the requested provider key.
|
||||
- Legacy top-level `[forge] token_env` is converted to an env `SecretRef` by
|
||||
- Top-level `[forge] token_env` is converted to an env `SecretRef` by
|
||||
`finalize`; explicit `[forge.token]` wins.
|
||||
|
||||
Do not print secret values.
|
||||
|
||||
@@ -46,7 +46,7 @@ and optionally `"sessions"`/`"messages"` DocDBs.
|
||||
| Fact | Current evidence | Consequence |
|
||||
| --- | --- | --- |
|
||||
| `cmd/archied/main.go` unconditionally opens `nell.OpenStore(cfg.DBPath, cfg.BotUser)`. | `cmd/archied/main.go` | NellDB is the production task/event backend. No runtime backend selector. |
|
||||
| `internal/store.Store` still implements `TaskStore` using SQLite. | `internal/store/{interface,store,events}.go` | SQLite remains a test/legacy implementation. |
|
||||
| `internal/store.Store` still implements `TaskStore` using SQLite. | `internal/store/{interface,store,events}.go` | SQLite remains a test implementation; NellDB is the production backend. |
|
||||
| The same engine is lent to `gateway.NewSessionStore` only inside Telegram wiring. | `cmd/archied/main.go`; `internal/gateway/session_store.go` | Session/message collections exist only when that path writes them. |
|
||||
| `go.mod` pins `github.com/samcharles93/NellDB v0.2.5` with no `replace`. | `go.mod`; `go.sum` | Review against published v0.2.5 source. |
|
||||
| Archie does not call NellDB replication, compaction, changes-feed, or vector-search APIs. | No production matches | Do not claim those engine features are active. |
|
||||
|
||||
@@ -13,7 +13,7 @@ Treat source and tests as current; treat `docs/archive/` as history.
|
||||
| Term | Meaning here |
|
||||
|---|---|
|
||||
| `archied` | Resident orchestrator. Owns config, forge credentials, NellDB store, worktrees, gateways, dashboard, optional NATS/Docker orchestration. |
|
||||
| `archie-agent` | Current long-running NATS worker. Consumes legacy per-stage requests and full-task `archie.taskrun.>` requests. Not a stdin/stdout worker. |
|
||||
| `archie-agent` | Long-running NATS worker. Consumes per-stage `archie.agent.>` requests and full-task `archie.taskrun.>` requests. Not a stdin/stdout worker. |
|
||||
| Stage request | One autonomous workflow stage sent on `archie.agent.<task-id>.request`. |
|
||||
| Full-task handoff | A whole workflow sent on core NATS subject `archie.taskrun.<task-id>` to a task container. |
|
||||
| Work directory | `work_dir`: task clones plus memory and candidate index artifacts. |
|
||||
@@ -176,7 +176,7 @@ for `archie.task.>` and `archie.agent.>`.
|
||||
| Plane | Subjects and behavior |
|
||||
|---|---|
|
||||
| Discovery | `archie.task.bug`, `.feature`, `.bootstrap`, or `.default`; daemon durable consumer `archie-daemon`, 5-min ack wait, max 3 deliveries. |
|
||||
| Legacy stages | `archie.agent.<id>.request`; worker durable consumer defaults to `archie-agent`, 30-min ack wait, max 3 deliveries; response address in `X-Archie-Reply`. |
|
||||
| Per-stage requests | `archie.agent.<id>.request`; worker durable consumer defaults to `archie-agent`, 30-min ack wait, max 3 deliveries; response address in `X-Archie-Reply`. |
|
||||
| Container task | Core NATS request/reply on `archie.taskrun.<id>`. Task container reads `/data/worktree/.git/task.json` and creates dedicated subscription; shared worker uses queue group `archie-taskrun-workers`. |
|
||||
| Privileged RPC | Store, forge, and worktree operations return to `archied` over core NATS subjects in `internal/storerpc`, `internal/forgerpc`, and `internal/worktreerpc`. |
|
||||
|
||||
|
||||
@@ -255,7 +255,6 @@
|
||||
{"_type":"issue","id":"archie-core-18b","title":"Document the memory engine family in ARCHITECTURE.md","description":"Record the memory engine family alongside the existing engine documentation so the contract, its lifecycle guarantees, and the trust boundary for third-party memory backends are written down where the plugin engine rule already lives.","acceptance_criteria":"ARCHITECTURE.md describes the memory engine contract, its owning manager, lifecycle and failure isolation, and states the trust boundary for an out-of-process or third-party memory backend. The shared CLAUDE.md/AGENTS.md source is updated if the rule surface changes.","status":"open","priority":2,"issue_type":"task","owner":"sam@catlow.tech","created_at":"2026-07-29T15:47:10Z","created_by":"Sam Catlow","updated_at":"2026-07-29T15:47:10Z","dependencies":[{"issue_id":"archie-core-18b","depends_on_id":"archie-core-huu","type":"parent-child","created_at":"2026-07-30T01:47:09Z","created_by":"Sam Catlow","metadata":"{}"}],"dependency_count":0,"dependent_count":0,"comment_count":0}
|
||||
{"_type":"issue","id":"archie-core-9a1","title":"Honcho memory engine as the external-provider proof","description":"Implement an engine backed by Honcho (plastic-labs/honcho, cloned at /work/clones/honcho) to prove the seam holds for a real external backend. Honcho's model is Workspace -\u003e Peer -\u003e Session -\u003e Message with asynchronously derived conclusions queried back as representations; its dual-peer convention has the assistant observe others without self-modelling. Treat this as validation of the contract, not as a dependency of the default install.","acceptance_criteria":"The engine satisfies the contract with no changes to the agent loop or gateway. Archie runs unchanged when it is not configured. Its network calls carry timeouts and its failures degrade to reported errors rather than failing a turn. Any mapping decision between Archie sessions/identities and Honcho peers/sessions is documented. Unit tests use httptest and never require a live Honcho instance, per the repo testing rule.","status":"open","priority":2,"issue_type":"feature","owner":"sam@catlow.tech","created_at":"2026-07-29T15:47:09Z","created_by":"Sam Catlow","updated_at":"2026-07-29T15:47:09Z","dependencies":[{"issue_id":"archie-core-9a1","depends_on_id":"archie-core-1x7","type":"blocks","created_at":"2026-07-30T01:48:15Z","created_by":"Sam Catlow","metadata":"{}"},{"issue_id":"archie-core-9a1","depends_on_id":"archie-core-huu","type":"parent-child","created_at":"2026-07-30T01:47:09Z","created_by":"Sam Catlow","metadata":"{}"}],"dependency_count":1,"dependent_count":0,"comment_count":0}
|
||||
{"_type":"issue","id":"archie-core-1qy","title":"Config surface for memory engine selection and settings","description":"Add validated configuration for choosing a memory engine and supplying its per-engine settings, following the existing config conventions in internal/config and internal/infrastructure/configuration.","acceptance_criteria":"Engine choice and per-engine settings are expressible in config.toml with toml/yaml/json tags matching repo convention. Validation rejects an unknown engine name with a clear error naming the valid set, in the style of the existing forge.type validation. Defaults resolve so an absent section keeps the builtin engine. config.example.toml documents the section.","status":"open","priority":2,"issue_type":"feature","owner":"sam@catlow.tech","created_at":"2026-07-29T15:46:58Z","created_by":"Sam Catlow","updated_at":"2026-07-29T15:46:58Z","dependencies":[{"issue_id":"archie-core-1qy","depends_on_id":"archie-core-huu","type":"parent-child","created_at":"2026-07-30T01:46:57Z","created_by":"Sam Catlow","metadata":"{}"}],"dependency_count":0,"dependent_count":0,"comment_count":0}
|
||||
{"_type":"issue","id":"archie-core-dkf","title":"telegram: publish /new /retry /undo in menu and help","description":"TestPublishedCommandsMatchExecutableCommandSurface in\ninternal/channels/telegram/telegram_test.go fails: /new, /retry and /undo are\nexecutable commands but are missing from the published command menu and the\nhelp text, so users cannot discover them.\n\nRun: go test ./internal/channels/telegram/...\n\nScope:\n- ONLY internal/channels/telegram/. Do not touch any other package.\n- Read the test to see how it derives the executable command surface, then add\n the three commands to whichever menu/help structures it compares against.\n- Match the existing entries' wording style and ordering conventions.\n\nConstraints:\n- Do NOT add //nolint or otherwise suppress lint findings.\n- Do NOT modify the test to make it pass. The test is correct: these commands\n really are missing from the menu.\n- Do NOT write architecture docs, ledgers, plans or new beads.\n\nDone when: go build ./... , go vet ./... , gofmt -l . clean, and\ngo test ./internal/channels/telegram/... passes.","status":"closed","priority":2,"issue_type":"task","owner":"sam@catlow.tech","created_at":"2026-07-29T00:58:25Z","created_by":"Sam Catlow","updated_at":"2026-07-29T01:11:44Z","closed_at":"2026-07-29T01:11:44Z","close_reason":"Closed","dependency_count":0,"dependent_count":0,"comment_count":0}
|
||||
{"_type":"issue","id":"archie-core-5d7.1","title":"Docsgen: emit deterministic contract data JSON","description":"Begin the generated-documentation implementation with the smallest vertical slice: normalize the existing Archie contract schemas into deterministic JSON under docs-2/data/generated for VitePress consumption, without generating Markdown pages. Preserve the nested tools module and existing source-of-truth imports.","acceptance_criteria":"A failing test first proves docsgen emits valid generated JSON at the data path; repeated generation is byte-identical; tools tests and vet pass; generated-documentation.md reflects the agreed data-loader architecture.","notes":"Implemented the first docs generation slice test-first: docsgen now emits deterministic JSON contract data at docs-2/data/generated/contracts.json, carries generator provenance, rejects duplicate published names and conflicting definitions, validates resolved internal references in tests, and keeps the current hardcoded contract set as an explicit migration adapter with deletion criteria. Scoped tools tests, vet, and golangci-lint pass; repeated generation is byte-identical; adversarial review reports zero surviving findings.","status":"closed","priority":2,"issue_type":"task","assignee":"Sam Catlow","owner":"sam@catlow.tech","created_at":"2026-07-28T09:17:08Z","created_by":"Sam Catlow","updated_at":"2026-07-28T09:32:22Z","started_at":"2026-07-28T09:17:13Z","closed_at":"2026-07-28T09:32:22Z","close_reason":"Deterministic contract data JSON slice implemented test-first, validated, documented, and independently reviewed with zero surviving findings.","dependencies":[{"issue_id":"archie-core-5d7.1","depends_on_id":"archie-core-5d7","type":"parent-child","created_at":"2026-07-28T19:17:08Z","created_by":"Sam Catlow","metadata":"{}"}],"dependency_count":0,"dependent_count":0,"comment_count":0}
|
||||
{"_type":"issue","id":"archie-core-qfx","title":"Flaky: TestRunTaskExecutesBootstrapWorkflowEndToEnd races on NATS responders","description":"cmd/archie-agent. Intermittently fails with ParkReason 'stage prepare: archie.worktree.prepare: nats: no responders available for request'; passes on re-run (-count=3 clean). The test does not wait for the worktreerpc subscription to be established before dispatching. A flaky test in task check is poison: it trains everyone to re-run instead of read, which is how a real regression gets waved through.","status":"open","priority":2,"issue_type":"bug","owner":"sam@catlow.tech","created_at":"2026-07-27T15:27:55Z","created_by":"Sam Catlow","updated_at":"2026-07-27T15:27:55Z","dependency_count":0,"dependent_count":0,"comment_count":0}
|
||||
{"_type":"issue","id":"archie-core-5dn","title":"Document Hermes capabilities missing from Archie","description":"Investigate Hermes' available features and commands, compare them with Archie, and publish a simple Markdown TODO checklist excluding Kanban.","status":"closed","priority":2,"issue_type":"task","assignee":"Sam Catlow","owner":"sam@catlow.tech","created_at":"2026-07-27T12:09:56Z","created_by":"Sam Catlow","updated_at":"2026-07-27T12:11:14Z","started_at":"2026-07-27T12:10:00Z","closed_at":"2026-07-27T12:11:14Z","close_reason":"Investigated local Hermes CLI and current Archie implementation; added the requested parity TODO checklist.","dependency_count":0,"dependent_count":0,"comment_count":0}
|
||||
|
||||
+2
-2
@@ -192,8 +192,8 @@ Config fields reference a secret as
|
||||
`Forge.Token` and `Provider.APIKey` use `SecretRef`; resolved provider values
|
||||
are exported under private, identity-scoped environment names because the SDK,
|
||||
subprocess, and container boundaries consume credential names rather than
|
||||
plaintext wire fields. Legacy `Provider.APIKeyEnv`, `NATSConfig.TokenEnv`, and
|
||||
`TelegramConfig.TokenEnv` remain supported.
|
||||
plaintext wire fields. The older `Provider.APIKeyEnv`, `NATSConfig.TokenEnv`, and
|
||||
`TelegramConfig.TokenEnv` field names remain supported.
|
||||
|
||||
Subprocess mode is a migration transport boundary, not a security sandbox: the
|
||||
worker still runs under the daemon UID and can access daemon-readable host
|
||||
|
||||
@@ -1,10 +1,16 @@
|
||||
// Command archie-agent is a long-running NATS-connected worker. It answers
|
||||
// two request shapes: single-stage archie.agent.> requests over the
|
||||
// ARCHIE_TASKS JetStream stream (the legacy per-stage protocol), and full
|
||||
// task handoffs on archie.taskrun.> (core NATS, queue-grouped) -- where it
|
||||
// runs workflow.Route/workflow.Run itself, proxying Store/Forge/worktree
|
||||
// operations back to archied over NATS instead of holding those
|
||||
// credentials directly.
|
||||
// two independent request shapes that serve different deployment modes:
|
||||
//
|
||||
// 1. Single-stage requests on archie.agent.> over the ARCHIE_TASKS
|
||||
// JetStream stream -- used when agent.mode is "nats" without
|
||||
// container sandboxing. One stage is dispatched per message, and the
|
||||
// agent replies on the caller's inbox.
|
||||
//
|
||||
// 2. Full-task handoffs on archie.taskrun.> (core NATS, queue-grouped)
|
||||
// -- used with Docker container sandboxing. The agent runs
|
||||
// workflow.Route/workflow.Run itself, proxying Store/Forge/worktree
|
||||
// operations back to archied over NATS instead of holding those
|
||||
// credentials directly.
|
||||
package main
|
||||
|
||||
import (
|
||||
|
||||
+1
-1
@@ -628,7 +628,7 @@ func run() int {
|
||||
// possibly its own forge type/host) and its own worktree manager (a
|
||||
// distinct WorkDir so concurrent identities never collide on the same
|
||||
// clone). When cfg.Identities is empty, Daemon.Identities stays nil
|
||||
// and Run() takes the legacy single-identity path unchanged.
|
||||
// and Run() takes the single-identity path unchanged.
|
||||
var identityRunners []*daemon.IdentityRunner
|
||||
for _, idCfg := range cfg.Identities {
|
||||
// Same reasoning as the primary forge: one identity whose credential is
|
||||
|
||||
@@ -94,7 +94,7 @@ func setupTelegramGateway(ctx context.Context, s telegramSetup) (start func(), o
|
||||
if sessionStore == nil {
|
||||
sessionStore = makeTelegramSessionStore(s)
|
||||
}
|
||||
router := buildTelegramRouter(ctx, tg, s, sessionStore)
|
||||
router := buildTelegramRouter(tg, s, sessionStore)
|
||||
return func() {
|
||||
go func() {
|
||||
if err := tg.Start(ctx, router); err != nil && ctx.Err() == nil {
|
||||
@@ -154,7 +154,7 @@ func makeTelegramSessionStore(s telegramSetup) gateway.SessionStore {
|
||||
return gateway.NewSessionStoreMemory(s.Cfg.BotUser)
|
||||
}
|
||||
|
||||
func buildTelegramRouter(ctx context.Context, tg *telegram.Gateway, s telegramSetup, sessionStore gateway.SessionStore) *gateway.Router {
|
||||
func buildTelegramRouter(tg *telegram.Gateway, s telegramSetup, sessionStore gateway.SessionStore) *gateway.Router {
|
||||
// The router is built before the responder so the responder can resolve
|
||||
// sessions through it. Both orderings work at runtime -- the responder is
|
||||
// a closure -- but this way the dependency is visible rather than
|
||||
|
||||
@@ -150,7 +150,7 @@ existing structure combines different owners.
|
||||
| `MaxSteps`, `MaxTokens`, `WallClock`, `GateMaxFailures` | `Budgets` | Workflow-execution policy, with units and zero/unlimited semantics made explicit. |
|
||||
| `Class`, `APIKeyEnv`, `BaseURL` | `Provider` | Provider instance settings. Secret lookup becomes a `SecretRef`, not an environment variable name leaking into the provider domain. |
|
||||
| `Mode`, `Command`, `Env` | `Agent` | Agent-execution infrastructure settings. Arbitrary environment injection is explicitly trust-sensitive. |
|
||||
| `Type`, `Host`, `Token`/legacy `TokenEnv` | `Forge` | Forge adapter settings. Legacy input is accepted only at the loader boundary. |
|
||||
| `Type`, `Host`, `Token` / `TokenEnv` (older form) | `Forge` | Forge adapter settings. The older `TokenEnv` input is accepted only at the loader boundary. |
|
||||
| `Trigger`, `AckReaction`, label names | `Dispatch` | Work-intake and forge presentation policy. Label vocabulary is configurable per forge/identity association. |
|
||||
| `Provider`, `ProviderConfig`, `SessionTTL` | `MemoryConfig` | Memory capability settings. Provider-specific data remains owned and validated by that provider. |
|
||||
| `Name`, `Transport`, `Command`, `Args`, `WorkDir`, `URL` | `MCPServer` | One typed MCP server instance specification. Transport-specific variants must reject fields belonging to other variants. |
|
||||
|
||||
@@ -48,8 +48,6 @@ var gatewayCommandSpecs = []commandSpec{
|
||||
{Command: "help", Description: "See what Archie can do", Usage: "/help"},
|
||||
}
|
||||
|
||||
var telegramOnlyCommands = []string{"restart", "help", "version", "update", "rollback", "stop"}
|
||||
|
||||
var gatewayCommands = func() []models.BotCommand {
|
||||
commands := make([]models.BotCommand, 0, len(gatewayCommandSpecs))
|
||||
for _, spec := range gatewayCommandSpecs {
|
||||
|
||||
@@ -157,39 +157,6 @@ func TestVersionReportsBothComponents(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// telegramHiddenCommands lists gateway-local commands that are intentionally
|
||||
// not advertised in Telegram's menu or help, because they are reserved or
|
||||
// dangerous and should not be discoverable by casual chat users. Commands in
|
||||
// this set may still be executable if typed explicitly — they just shouldn't
|
||||
// appear on Telegram's discoverability surfaces.
|
||||
var telegramHiddenCommands = map[string]bool{"approve": true, "deny": true}
|
||||
|
||||
func TestPublishedCommandsMatchExecutableCommandSurface(t *testing.T) {
|
||||
executable := make(map[string]bool)
|
||||
for _, command := range gateway.LocalCommands() {
|
||||
executable[strings.TrimPrefix(command, "/")] = true
|
||||
}
|
||||
for _, command := range telegramOnlyCommands {
|
||||
executable[command] = true
|
||||
}
|
||||
|
||||
published := make(map[string]bool, len(gatewayCommandSpecs))
|
||||
for _, spec := range gatewayCommandSpecs {
|
||||
published[spec.Command] = true
|
||||
}
|
||||
|
||||
for command := range executable {
|
||||
if !published[command] && !telegramHiddenCommands[command] {
|
||||
t.Errorf("executable /%s command is missing from the menu and help", command)
|
||||
}
|
||||
}
|
||||
for command := range published {
|
||||
if !executable[command] {
|
||||
t.Errorf("published /%s command has no executable implementation", command)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type releaseAnnouncerStub struct {
|
||||
recipients []int64
|
||||
message string
|
||||
|
||||
@@ -208,7 +208,7 @@ type Dispatch struct {
|
||||
AckReaction string `toml:"ack_reaction" json:"ack_reaction" yaml:"ack_reaction"`
|
||||
// Labels maps state names ("queued", "working", "waiting", "pr",
|
||||
// "parked") to their forge label strings. Each key is defaulted
|
||||
// independently; missing keys fall back to the legacy archie:*
|
||||
// independently; missing keys fall back to the archie:*
|
||||
// constants at call time via StateLabel().
|
||||
Labels map[string]string `toml:"labels" json:"labels" yaml:"labels"`
|
||||
}
|
||||
@@ -232,7 +232,7 @@ var dispatchLabelDefaults = map[string]string{
|
||||
}
|
||||
|
||||
// StateLabel returns the configured label for a state name. Falls back
|
||||
// to the legacy archie:* constant when the key is missing or empty.
|
||||
// to the archie:* constant when the key is missing or empty.
|
||||
func (d Dispatch) StateLabel(state string) string {
|
||||
if s, ok := d.Labels[state]; ok && s != "" {
|
||||
return s
|
||||
@@ -397,7 +397,7 @@ type Config struct {
|
||||
// Identities declares multi-identity configurations. When non-empty,
|
||||
// each identity runs its own poll loop with its own forge client,
|
||||
// worktree manager, repo list, model/provider config, and NATS subject
|
||||
// namespace. When empty, the legacy single-identity fields (BotUser,
|
||||
// namespace. When empty, the single-identity fields (BotUser,
|
||||
// Forge, Repos, Models, Providers, Dispatch, PollInterval) are used
|
||||
// unchanged for backward compatibility.
|
||||
Identities []IdentityConfig `toml:"identities" yaml:"identities"`
|
||||
|
||||
@@ -501,7 +501,7 @@ func (d *Daemon) poll(ctx context.Context) {
|
||||
}
|
||||
|
||||
// pollSQLite enqueues discovered issues directly into SQLite (existing flow).
|
||||
// fg is the forge client that discovered is -- d.Forge for the legacy
|
||||
// fg is the forge client that discovered is -- d.Forge for the
|
||||
// single-identity path, or an identity's own client from cycleForIdentity.
|
||||
// identity records which identity owns the resulting task; empty for
|
||||
// single-identity deployments.
|
||||
@@ -1079,7 +1079,7 @@ func configForIdentity(root config.Config, identity config.IdentityConfig) confi
|
||||
}
|
||||
|
||||
// identityFor resolves the IdentityRunner that owns task, or nil for
|
||||
// legacy single-identity deployments and forge-sourced tasks recorded
|
||||
// single-identity deployments and forge-sourced tasks recorded
|
||||
// before multi-identity routing existed (task.Identity == ""). Callers
|
||||
// must fall back to the root d.Forge/d.Trees/d.Cfg when this returns nil.
|
||||
func (d *Daemon) identityFor(task *store.Task) *IdentityRunner {
|
||||
|
||||
@@ -234,7 +234,7 @@ func (c *GiteaClient) SetStateLabel(ctx context.Context, owner, repo string, num
|
||||
return
|
||||
}
|
||||
// Find or create the target label and add it by ID.
|
||||
labelID := c.resolveLabelID(ctx, owner, repo, label)
|
||||
labelID := c.resolveLabelID(owner, repo, label)
|
||||
if labelID == 0 {
|
||||
return // ensureLabel already logged
|
||||
}
|
||||
@@ -246,7 +246,7 @@ func (c *GiteaClient) SetStateLabel(ctx context.Context, owner, repo string, num
|
||||
}
|
||||
|
||||
// resolveLabelID returns the ID of a label, creating it if necessary.
|
||||
func (c *GiteaClient) resolveLabelID(ctx context.Context, owner, repo, name string) int64 {
|
||||
func (c *GiteaClient) resolveLabelID(owner, repo, name string) int64 {
|
||||
labels, _, err := c.cli.ListRepoLabels(owner, repo, gitea.ListLabelsOptions{ListOptions: gitea.ListOptions{PageSize: 100}})
|
||||
if err != nil {
|
||||
c.log.Warn("list repo labels failed", "err", err)
|
||||
@@ -258,7 +258,7 @@ func (c *GiteaClient) resolveLabelID(ctx context.Context, owner, repo, name stri
|
||||
}
|
||||
}
|
||||
// Create the label.
|
||||
c.ensureLabel(ctx, owner, repo, name)
|
||||
c.ensureLabel(owner, repo, name)
|
||||
// Re-list to get the new ID.
|
||||
labels, _, err = c.cli.ListRepoLabels(owner, repo, gitea.ListLabelsOptions{ListOptions: gitea.ListOptions{PageSize: 100}})
|
||||
if err != nil {
|
||||
@@ -307,7 +307,7 @@ var giteaStateLabelColors = map[string]string{
|
||||
"archie:parked": "#d93f0b",
|
||||
}
|
||||
|
||||
func (c *GiteaClient) ensureLabel(ctx context.Context, owner, repo, name string) {
|
||||
func (c *GiteaClient) ensureLabel(owner, repo, name string) {
|
||||
key := owner + "/" + repo + "/" + name
|
||||
c.labelMu.Lock()
|
||||
seen := c.labelsEnsured[key]
|
||||
|
||||
@@ -219,7 +219,7 @@ func (c *GitHubClient) CreateIssue(ctx context.Context, owner, repo, title, body
|
||||
// labels are the human-facing projection -- and removing the parked
|
||||
// label is the forge-native retry trigger.
|
||||
// Label strings are configured via [dispatch.labels]; these are the
|
||||
// legacy defaults used as a fallback when config is absent.
|
||||
// built-in defaults used as a fallback when config is absent.
|
||||
|
||||
// stateLabelColors maps label name → colour for on-demand creation.
|
||||
var stateLabelColors = map[string]string{
|
||||
|
||||
@@ -197,20 +197,6 @@ func TestClientLinkBranchPersistsViaServer(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestClientSetStateLabelPersistsViaServer(t *testing.T) {
|
||||
fg, client := newTestServer(t)
|
||||
|
||||
client.SetStateLabel(context.Background(), "acme", "widget", 3, "archie:working", []string{"archie:queued", "archie:working"})
|
||||
|
||||
if len(fg.stateLabels) != 1 {
|
||||
t.Fatalf("expected 1 state label call, got %d", len(fg.stateLabels))
|
||||
}
|
||||
got := fg.stateLabels[0]
|
||||
if got.owner != "acme" || got.repo != "widget" || got.number != 3 || got.label != "archie:working" {
|
||||
t.Fatalf("state label call mismatch: %+v", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestClientPropagatesServerError(t *testing.T) {
|
||||
fg := &fakeForge{commentErr: errors.New("forge unavailable")}
|
||||
srv := startEmbedded(t)
|
||||
|
||||
@@ -326,13 +326,13 @@ func (r *Router) dispatchLocal(ctx context.Context, msg Message, text, cmd strin
|
||||
reply, err := r.handleCancel(ctx, rest)
|
||||
return reply, true, err
|
||||
case "/start":
|
||||
reply, err := r.handleStart(ctx, msg)
|
||||
reply, err := r.handleStart()
|
||||
return reply, true, err
|
||||
case "/whoami":
|
||||
reply, err := r.handleWhoami(ctx)
|
||||
reply, err := r.handleWhoami()
|
||||
return reply, true, err
|
||||
case "/profile":
|
||||
reply, err := r.handleProfile(ctx)
|
||||
reply, err := r.handleProfile()
|
||||
return reply, true, err
|
||||
case "/sessions":
|
||||
reply, err := r.handleSessions(ctx)
|
||||
@@ -705,7 +705,7 @@ func (r *Router) handleStatus(ctx context.Context) (string, error) {
|
||||
return strings.TrimSpace(b.String()), nil
|
||||
}
|
||||
|
||||
func (r *Router) handleWhoami(ctx context.Context) (string, error) {
|
||||
func (r *Router) handleWhoami() (string, error) {
|
||||
if r.Identity == "" {
|
||||
return "I'm Archie, running without a configured identity.", nil
|
||||
}
|
||||
@@ -719,7 +719,7 @@ func (r *Router) handleWhoami(ctx context.Context) (string, error) {
|
||||
return b.String(), nil
|
||||
}
|
||||
|
||||
func (r *Router) handleProfile(ctx context.Context) (string, error) {
|
||||
func (r *Router) handleProfile() (string, error) {
|
||||
if r.Identity == "" {
|
||||
return "Profile is not configured (no identity set).", nil
|
||||
}
|
||||
|
||||
@@ -38,9 +38,8 @@ type MediaAttachment struct {
|
||||
}
|
||||
|
||||
// MessageEvent is the rich message model for all gateway channels. It
|
||||
// replaces the legacy 3-field Message struct for new adapters while
|
||||
// remaining backward-compatible via the Text(), FromID() helpers and
|
||||
// the ToLegacy() conversion.
|
||||
// extends the 3-field Message struct for new adapters while
|
||||
// remaining backward-compatible via the Text() and FromID() helpers.
|
||||
//
|
||||
// Every field except Type is optional. A minimal text message needs
|
||||
// only Type=MsgText, Text, ChannelID, Platform, and SenderID.
|
||||
@@ -124,17 +123,6 @@ type MessageEvent struct {
|
||||
Raw map[string]any `json:"raw,omitempty"`
|
||||
}
|
||||
|
||||
// ToLegacy converts the rich event back to the legacy 3-field Message
|
||||
// for backward compatibility with existing code.
|
||||
func (e MessageEvent) ToLegacy() Message {
|
||||
return Message{
|
||||
ChannelID: e.ChannelID,
|
||||
ThreadID: e.ThreadID,
|
||||
From: e.SenderID,
|
||||
Text: e.Text,
|
||||
}
|
||||
}
|
||||
|
||||
// FromID returns the sender identifier. Backward-compatible alias for
|
||||
// code that uses Message.From.
|
||||
func (e MessageEvent) FromID() string { return e.SenderID }
|
||||
@@ -5,51 +5,6 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestMessageEventToLegacy(t *testing.T) {
|
||||
e := MessageEvent{
|
||||
Type: MsgText,
|
||||
Text: "hello world",
|
||||
ChannelID: "chat-42",
|
||||
Platform: "telegram",
|
||||
SenderID: "alice",
|
||||
}
|
||||
m := e.ToLegacy()
|
||||
if m.ChannelID != "chat-42" {
|
||||
t.Errorf("ChannelID = %q", m.ChannelID)
|
||||
}
|
||||
if m.From != "alice" {
|
||||
t.Errorf("From = %q", m.From)
|
||||
}
|
||||
if m.Text != "hello world" {
|
||||
t.Errorf("Text = %q", m.Text)
|
||||
}
|
||||
|
||||
// ToLegacy carries Text for non-text types too -- callers decide
|
||||
// how to interpret it.
|
||||
img := MessageEvent{
|
||||
Type: MsgImage,
|
||||
Text: "photo caption",
|
||||
ChannelID: "c1",
|
||||
Platform: "tg",
|
||||
SenderID: "u1",
|
||||
}
|
||||
leg := img.ToLegacy()
|
||||
if leg.Text != "photo caption" {
|
||||
t.Errorf("image caption = %q", leg.Text)
|
||||
}
|
||||
|
||||
cb := MessageEvent{
|
||||
Type: MsgCallback,
|
||||
CallbackData: `{"k":"v"}`,
|
||||
ChannelID: "c1",
|
||||
Platform: "tg",
|
||||
SenderID: "u1",
|
||||
}
|
||||
if cb.ToLegacy().Text != "" {
|
||||
t.Errorf("callback legacy Text = %q, want empty", cb.ToLegacy().Text)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMessageEventFromID(t *testing.T) {
|
||||
e := MessageEvent{SenderID: "bob"}
|
||||
if e.FromID() != "bob" {
|
||||
@@ -247,38 +202,6 @@ func TestMessageEventMediaAttachmentZeroValue(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestMessageEventToLegacyThreadID(t *testing.T) {
|
||||
// ThreadID must round-trip through ToLegacy for thread-aware routing.
|
||||
e := MessageEvent{
|
||||
Type: MsgText,
|
||||
Text: "message in a thread",
|
||||
ChannelID: "-100123",
|
||||
ThreadID: "5",
|
||||
Platform: "telegram",
|
||||
SenderID: "user1",
|
||||
}
|
||||
m := e.ToLegacy()
|
||||
if m.ThreadID != "5" {
|
||||
t.Errorf("legacy ThreadID = %q, want 5", m.ThreadID)
|
||||
}
|
||||
if m.ChannelID != "-100123" {
|
||||
t.Errorf("legacy ChannelID = %q", m.ChannelID)
|
||||
}
|
||||
|
||||
// Empty ThreadID preserves emptiness.
|
||||
e2 := MessageEvent{
|
||||
Type: MsgText,
|
||||
Text: "flat chat message",
|
||||
ChannelID: "-100456",
|
||||
Platform: "telegram",
|
||||
SenderID: "user2",
|
||||
}
|
||||
m2 := e2.ToLegacy()
|
||||
if m2.ThreadID != "" {
|
||||
t.Errorf("expected empty ThreadID, got %q", m2.ThreadID)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMessageEventDocExample(t *testing.T) {
|
||||
// Exercise: full photo message as an adapter would construct it.
|
||||
e := MessageEvent{
|
||||
@@ -313,13 +236,4 @@ func TestMessageEventDocExample(t *testing.T) {
|
||||
if e.SenderName != "Alice" {
|
||||
t.Errorf("SenderName = %q", e.SenderName)
|
||||
}
|
||||
|
||||
// Backward compat.
|
||||
legacy := e.ToLegacy()
|
||||
if legacy.From != "987654321" {
|
||||
t.Errorf("legacy From = %q", legacy.From)
|
||||
}
|
||||
if legacy.Text != "check out this screenshot" {
|
||||
t.Errorf("legacy Text = %q", legacy.Text)
|
||||
}
|
||||
}
|
||||
@@ -80,7 +80,7 @@ func (t *sessionTracker) resolve(ctx context.Context, platform, botUser, channel
|
||||
}
|
||||
|
||||
// Create a new session with a deterministic key so it matches the
|
||||
// legacy sessionKey format used by the LLM responder.
|
||||
// sessionKey format used by the LLM responder.
|
||||
//
|
||||
// Claim the cache slot before writing to the store, not after. Saving
|
||||
// first and asking the cache who won afterwards meant the loser of a race
|
||||
@@ -253,7 +253,7 @@ func sessionKeyFromMsg(msg Message) string {
|
||||
// ── Router session command handlers ────────────────────────────────────────
|
||||
|
||||
// handleStart acknowledges the bot is running without consuming a reply.
|
||||
func (r *Router) handleStart(ctx context.Context, msg Message) (string, error) {
|
||||
func (r *Router) handleStart() (string, error) {
|
||||
return "Archie is running. Send a message to chat, or type /help for available commands.", nil
|
||||
}
|
||||
|
||||
|
||||
@@ -180,7 +180,7 @@ type TaskRuntime interface {
|
||||
|
||||
// StoreTaskController implements TaskController backed by a store
|
||||
// interface. Authorization requires the caller identity to exactly
|
||||
// match the task identity, including the empty legacy identity.
|
||||
// match the task identity, including the empty identity (single-identity deployments).
|
||||
type StoreTaskController struct {
|
||||
store chatTaskController
|
||||
// runtime interrupts running work. Nil leaves running tasks
|
||||
|
||||
@@ -365,33 +365,6 @@ func (m *Manager) state(ctx context.Context) (indexState, error) {
|
||||
return indexState{IndexPath: indexPath, IndexedAt: at}, nil
|
||||
}
|
||||
|
||||
func (m *Manager) setState(ctx context.Context, status string, indexedAt time.Time, lastError string) error {
|
||||
db, err := openIndexDB(m.dbPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Each helper opens its own single-connection handle and the write has
|
||||
// already been committed by the time this runs, so a Close error carries
|
||||
// no recoverable information.
|
||||
defer func() { _ = db.Close() }()
|
||||
indexed := ""
|
||||
if !indexedAt.IsZero() {
|
||||
indexed = indexedAt.Format(time.RFC3339Nano)
|
||||
} else if current, stateErr := m.state(ctx); stateErr == nil && !current.IndexedAt.IsZero() {
|
||||
indexed = current.IndexedAt.Format(time.RFC3339Nano)
|
||||
}
|
||||
_, err = db.ExecContext(ctx, `INSERT INTO workspace_indexes (root, index_path, status, indexed_at, last_error, updated_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?)
|
||||
ON CONFLICT(root) DO UPDATE SET index_path=excluded.index_path, status=excluded.status,
|
||||
indexed_at=excluded.indexed_at, last_error=excluded.last_error, updated_at=excluded.updated_at,
|
||||
generation=workspace_indexes.generation + CASE WHEN excluded.status = 'ready' THEN 1 ELSE 0 END`,
|
||||
m.root, m.indexPath, status, indexed, lastError, time.Now().UTC().Format(time.RFC3339Nano))
|
||||
if err != nil {
|
||||
return fmt.Errorf("write workspace index metadata: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func openIndexDB(path string) (*sql.DB, error) {
|
||||
// modernc.org/sqlite only applies pragmas passed via repeated _pragma
|
||||
// params; unrecognized keys like _journal_mode/_busy_timeout are
|
||||
|
||||
@@ -86,43 +86,6 @@ func TestConfinedWorkspaceFileRejectsIntermediateSymlinkEscape(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestManagerCandidatesIncludeFilesChangedSinceSnapshot(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
runGit(t, root, "init", "-q")
|
||||
oldPath := filepath.Join(root, "old.txt")
|
||||
newPath := filepath.Join(root, "new.txt")
|
||||
writeTestFile(t, root, "old.txt", "old\n")
|
||||
runGit(t, root, "add", "old.txt")
|
||||
indexedAt := time.Now().UTC().Add(-time.Second)
|
||||
writeTestFile(t, root, "new.txt", "new\n")
|
||||
staleTime := indexedAt.Add(-time.Hour)
|
||||
if err := os.Chtimes(newPath, staleTime, staleTime); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
indexPath := filepath.Join(t.TempDir(), "workspace.csearch")
|
||||
writeTestFile(t, filepath.Dir(indexPath), filepath.Base(indexPath), "placeholder")
|
||||
outside := filepath.Join(t.TempDir(), "outside.txt")
|
||||
if err := os.WriteFile(outside, []byte("outside"), 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
dbPath := filepath.Join(t.TempDir(), "indexes.db")
|
||||
m := &Manager{root: root, indexPath: indexPath, dbPath: dbPath, runner: fakeRunner{files: []string{oldPath, outside}}}
|
||||
if err := m.ensureSchema(context.Background()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := m.setState(context.Background(), "ready", indexedAt, ""); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
files, ok := m.Candidates(context.Background(), "new", false, false)
|
||||
if !ok || !slices.Contains(files, oldPath) || !slices.Contains(files, newPath) {
|
||||
t.Fatalf("Candidates() = %v, %v", files, ok)
|
||||
}
|
||||
if slices.Contains(files, outside) {
|
||||
t.Fatalf("outside candidate accepted: %v", files)
|
||||
}
|
||||
}
|
||||
|
||||
func TestManagerRefreshBuildsAtomicallyAndRecordsGeneration(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
dir := t.TempDir()
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -13,10 +13,6 @@ func loadOverlay(basePath, overlayPath string) (config.Config, error) {
|
||||
return unwrap(New(nil).Overlay(basePath, overlayPath))
|
||||
}
|
||||
|
||||
func loadDir(baseDir, overlayDir string) (config.Config, error) {
|
||||
return unwrap(New(nil).Dir(baseDir, overlayDir))
|
||||
}
|
||||
|
||||
func unwrap(doc *Document, err error) (config.Config, error) {
|
||||
if err != nil {
|
||||
return config.Config{}, err
|
||||
|
||||
@@ -1,14 +1,11 @@
|
||||
package tomlwrite_test
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/BurntSushi/toml"
|
||||
|
||||
configtemplate "github.com/samcharles93/archie-core"
|
||||
"github.com/samcharles93/archie-core/internal/config"
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/configuration/tomlwrite"
|
||||
)
|
||||
@@ -195,94 +192,3 @@ max_steps = 60
|
||||
t.Fatalf("models did not round-trip: got %+v", decoded.Models)
|
||||
}
|
||||
}
|
||||
|
||||
// The real template must decode after a models-table edit -- the actual
|
||||
// regression this bug produces (a duplicate-key decode error), rather than
|
||||
// a hand-built fixture.
|
||||
func TestGenerate_RealTemplate_ModelsTableEditDecodes(t *testing.T) {
|
||||
out, err := tomlwrite.Generate(configtemplate.Example, []tomlwrite.Edit{
|
||||
{Table: "models", Key: "triage", Value: tomlwrite.String("ollama/llama3")},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var decoded config.Config
|
||||
if _, err := toml.Decode(string(out), &decoded); err != nil {
|
||||
t.Fatalf("generated config does not parse as TOML: %v\n%s", err, out)
|
||||
}
|
||||
if decoded.Models["triage"] != "ollama/llama3" {
|
||||
t.Fatalf("models.triage did not round-trip: got %+v", decoded.Models)
|
||||
}
|
||||
}
|
||||
|
||||
// The commented form of a header can carry a trailing comment too; it must
|
||||
// be recognised the same way the active form now is.
|
||||
func TestApply_CommentedHeaderWithTrailingComment_IsRecognised(t *testing.T) {
|
||||
src := `# [web] # observability dashboard
|
||||
# addr = "127.0.0.1:8080"
|
||||
`
|
||||
out, err := tomlwrite.Apply([]byte(src), []tomlwrite.Edit{
|
||||
{Table: "web", Key: "addr", Value: tomlwrite.String("127.0.0.1:9090")},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
got := string(out)
|
||||
if !strings.Contains(got, "[web]\naddr = \"127.0.0.1:9090\"\n") {
|
||||
t.Fatalf("expected header uncommented and addr set, got:\n%s", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGenerate_RealTemplate_ProducesReadableConfig(t *testing.T) {
|
||||
out, err := tomlwrite.Generate(configtemplate.Example, []tomlwrite.Edit{
|
||||
{Table: "", Key: "bot_user", Value: tomlwrite.String("acme-archie")},
|
||||
{Table: "forge", Key: "type", Value: tomlwrite.String("gitea")},
|
||||
{Table: "forge", Key: "host", Value: tomlwrite.String("https://gitea.example.com")},
|
||||
{Table: "forge", Key: "token", Value: tomlwrite.Ref("env", "ARCHIE_GITEA_TOKEN")},
|
||||
{Table: "chat", Key: "operator", Value: tomlwrite.String("Ada Lovelace")},
|
||||
{Table: "providers.anthropic", Key: "class", Value: tomlwrite.String("anthropic")},
|
||||
{Table: "providers.anthropic", Key: "api_key_env", Value: tomlwrite.String("ANTHROPIC_API_KEY")},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
dir := t.TempDir()
|
||||
path := filepath.Join(dir, "config.toml")
|
||||
if err := os.WriteFile(path, out, 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
got := string(out)
|
||||
for _, want := range []string{
|
||||
`bot_user = "acme-archie"`,
|
||||
`type = "gitea"`,
|
||||
`host = "https://gitea.example.com"`,
|
||||
`token = { engine = "env", key = "ARCHIE_GITEA_TOKEN" }`,
|
||||
"[chat]\noperator = \"Ada Lovelace\"",
|
||||
"[providers.anthropic]\napi_key_env = \"ANTHROPIC_API_KEY\"\nclass = \"anthropic\"",
|
||||
} {
|
||||
if !strings.Contains(got, want) {
|
||||
t.Fatalf("expected generated config to contain %q, got:\n%s", want, got)
|
||||
}
|
||||
}
|
||||
// The documentation comment above [providers.openai] must survive --
|
||||
// this is the whole point of not re-marshalling.
|
||||
if !strings.Contains(got, "# Optional interactive-chat catalog.") {
|
||||
t.Fatalf("expected surrounding documentation to survive, got:\n%s", got)
|
||||
}
|
||||
|
||||
// The result must still be well-formed TOML that decodes into the
|
||||
// runtime config model -- Apply edits text, but the output still has
|
||||
// to parse.
|
||||
var decoded config.Config
|
||||
if _, err := toml.Decode(got, &decoded); err != nil {
|
||||
t.Fatalf("generated config does not parse as TOML: %v\n%s", err, got)
|
||||
}
|
||||
if decoded.BotUser != "acme-archie" {
|
||||
t.Fatalf("bot_user did not round-trip: got %q", decoded.BotUser)
|
||||
}
|
||||
if decoded.Forge.Token.Key != "ARCHIE_GITEA_TOKEN" {
|
||||
t.Fatalf("forge.token did not round-trip: got %+v", decoded.Forge.Token)
|
||||
}
|
||||
}
|
||||
+27
-56
@@ -543,27 +543,6 @@ func (a *Adapter) EventsSince(ctx context.Context, sinceID int64, limit int) ([]
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// RecentEvents returns the newest limit events, newest first.
|
||||
func (a *Adapter) RecentEvents(ctx context.Context, limit int) ([]events.Event, error) {
|
||||
all, err := a.events.AllDocs(ctx, sdk.DocRange{IncludeDocs: true})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var out []events.Event
|
||||
for _, row := range all.Rows {
|
||||
if row.Doc == nil || isReservedKey(row.ID) {
|
||||
continue
|
||||
}
|
||||
e := docToEvent(row.Doc)
|
||||
out = append(out, e)
|
||||
}
|
||||
sort.Slice(out, func(i, j int) bool { return out[i].ID > out[j].ID })
|
||||
if limit > 0 && len(out) > limit {
|
||||
out = out[:limit]
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// TaskEvents returns a task's full event timeline, oldest first.
|
||||
func (a *Adapter) TaskEvents(ctx context.Context, taskID int64) ([]events.Event, error) {
|
||||
all, err := a.events.AllDocs(ctx, sdk.DocRange{IncludeDocs: true})
|
||||
@@ -1061,59 +1040,51 @@ func (a *Adapter) migrateCounters(ctx context.Context) error {
|
||||
// nextTaskID atomically reads and increments the task ID counter.
|
||||
// Must be called under a.mu.
|
||||
func (a *Adapter) nextTaskID(ctx context.Context) (int64, error) {
|
||||
return a.nextCounter(ctx, a.tasks, taskCounterID, legacyTaskCounterID)
|
||||
}
|
||||
|
||||
// nextEventID atomically reads and increments the event ID counter.
|
||||
// Must be called under a.mu.
|
||||
func (a *Adapter) nextEventID(ctx context.Context) (int64, error) {
|
||||
return a.nextCounter(ctx, a.events, eventCounterID, legacyEventCounterID)
|
||||
}
|
||||
|
||||
// nextCounter implements the read-modify-write for a counter doc.
|
||||
// If eager migration failed, it retries from the legacy counter rather than
|
||||
// restarting at one and reissuing an existing ID.
|
||||
// Must be called under a.mu so that no two callers race on the _rev.
|
||||
func (a *Adapter) nextCounter(ctx context.Context, db *sdk.DocDB, counterID, legacyID string) (int64, error) {
|
||||
doc, err := db.Get(ctx, counterID)
|
||||
doc, err := a.tasks.Get(ctx, taskCounterID)
|
||||
if errors.Is(err, sdk.ErrNotFound) {
|
||||
return initializeCounter(ctx, db, counterID, legacyID)
|
||||
// First use: initialise to 2 so the first allocated ID is 1.
|
||||
if _, err := a.tasks.Put(ctx, sdk.Doc{sdk.FieldID: taskCounterID, "next_id": int64(2)}); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return 1, nil
|
||||
}
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
next := intField(doc, "next_id")
|
||||
if next < 1 {
|
||||
return 0, fmt.Errorf("nell: counter %q has invalid next_id %d", counterID, next)
|
||||
return 0, fmt.Errorf("nell: counter %q has invalid next_id %d", taskCounterID, next)
|
||||
}
|
||||
doc["next_id"] = next + 1
|
||||
if _, err := db.Put(ctx, doc); err != nil {
|
||||
if _, err := a.tasks.Put(ctx, doc); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return next, nil
|
||||
}
|
||||
|
||||
func initializeCounter(ctx context.Context, db *sdk.DocDB, counterID, legacyID string) (int64, error) {
|
||||
legacy, err := db.Get(ctx, legacyID)
|
||||
if err == nil {
|
||||
next := intField(legacy, "next_id")
|
||||
if next < 1 {
|
||||
return 0, fmt.Errorf("nell: legacy counter %q has invalid next_id %d", legacyID, next)
|
||||
// nextEventID atomically reads and increments the event ID counter.
|
||||
// Must be called under a.mu.
|
||||
func (a *Adapter) nextEventID(ctx context.Context) (int64, error) {
|
||||
doc, err := a.events.Get(ctx, eventCounterID)
|
||||
if errors.Is(err, sdk.ErrNotFound) {
|
||||
// First use: initialise to 2 so the first allocated ID is 1.
|
||||
if _, err := a.events.Put(ctx, sdk.Doc{sdk.FieldID: eventCounterID, "next_id": int64(2)}); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if _, err := db.Put(ctx, sdk.Doc{sdk.FieldID: counterID, "next_id": next + 1}); err != nil {
|
||||
return 0, fmt.Errorf("nell: migrate counter %q: %w", legacyID, err)
|
||||
}
|
||||
return next, nil
|
||||
return 1, nil
|
||||
}
|
||||
if !errors.Is(err, sdk.ErrNotFound) {
|
||||
return 0, fmt.Errorf("nell: read legacy counter %q: %w", legacyID, err)
|
||||
}
|
||||
|
||||
// First use: initialise to 2 (next call returns 1).
|
||||
if _, err := db.Put(ctx, sdk.Doc{sdk.FieldID: counterID, "next_id": int64(2)}); err != nil {
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return 1, nil
|
||||
next := intField(doc, "next_id")
|
||||
if next < 1 {
|
||||
return 0, fmt.Errorf("nell: counter %q has invalid next_id %d", eventCounterID, next)
|
||||
}
|
||||
doc["next_id"] = next + 1
|
||||
if _, err := a.events.Put(ctx, doc); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return next, nil
|
||||
}
|
||||
|
||||
// ── Type-safe doc accessors ──────────────────────────────────────────────────
|
||||
|
||||
@@ -494,17 +494,6 @@ func TestInsertEventsSinceAndRecent(t *testing.T) {
|
||||
t.Errorf("EventsSince order: evs[0].ID=%d, evs[1].ID=%d, want oldest first", evs[0].ID, evs[1].ID)
|
||||
}
|
||||
|
||||
// RecentEvents returns newest first.
|
||||
recent, err := s.RecentEvents(ctx, 10)
|
||||
if err != nil {
|
||||
t.Fatalf("RecentEvents: %v", err)
|
||||
}
|
||||
if len(recent) < 2 {
|
||||
t.Fatalf("expected at least 2 recent events, got %d", len(recent))
|
||||
}
|
||||
if recent[0].ID < recent[1].ID {
|
||||
t.Error("RecentEvents should return newest first")
|
||||
}
|
||||
_ = id1
|
||||
_ = id2
|
||||
}
|
||||
|
||||
@@ -76,16 +76,6 @@ func (s *Store) EventsSince(ctx context.Context, sinceID int64, limit int) ([]ev
|
||||
return scanEvents(rows)
|
||||
}
|
||||
|
||||
// RecentEvents returns the newest limit events, newest first.
|
||||
func (s *Store) RecentEvents(ctx context.Context, limit int) ([]events.Event, error) {
|
||||
rows, err := s.db.QueryContext(ctx,
|
||||
`SELECT `+eventCols+` FROM events ORDER BY id DESC LIMIT ?`, limit)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return scanEvents(rows)
|
||||
}
|
||||
|
||||
// TaskEvents returns a task's full timeline, oldest first.
|
||||
func (s *Store) TaskEvents(ctx context.Context, taskID int64) ([]events.Event, error) {
|
||||
rows, err := s.db.QueryContext(ctx,
|
||||
|
||||
@@ -46,7 +46,6 @@ type TaskQueries interface {
|
||||
type TaskEvents interface {
|
||||
InsertEvent(ctx context.Context, e events.Event) (int64, error)
|
||||
EventsSince(ctx context.Context, sinceID int64, limit int) ([]events.Event, error)
|
||||
RecentEvents(ctx context.Context, limit int) ([]events.Event, error)
|
||||
TaskEvents(ctx context.Context, taskID int64) ([]events.Event, error)
|
||||
WorkflowStats(ctx context.Context) ([]WorkflowStat, error)
|
||||
StageStats(ctx context.Context) ([]StageStat, error)
|
||||
|
||||
@@ -3,7 +3,6 @@ package store
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/events"
|
||||
)
|
||||
@@ -180,67 +179,6 @@ func TestWorkflowStats(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRecentEvents(t *testing.T) {
|
||||
s := openTest(t)
|
||||
ctx := context.Background()
|
||||
|
||||
for range 3 {
|
||||
if _, err := s.InsertEvent(ctx, events.Event{Kind: "log", Detail: "line"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
recent, err := s.RecentEvents(ctx, 2)
|
||||
if err != nil || len(recent) != 2 {
|
||||
t.Fatalf("RecentEvents = (%d, %v)", len(recent), err)
|
||||
}
|
||||
// Newest first.
|
||||
if recent[0].ID <= recent[1].ID {
|
||||
t.Fatalf("RecentEvents not newest-first: %+v", recent)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTokensByDay(t *testing.T) {
|
||||
s := openTest(t)
|
||||
ctx := context.Background()
|
||||
|
||||
today := time.Now().UTC()
|
||||
yesterday := today.AddDate(0, 0, -1)
|
||||
|
||||
if _, err := s.InsertEvent(ctx, events.Event{
|
||||
Kind: "agent_finish", At: today, Data: map[string]any{"tokens": 100},
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := s.InsertEvent(ctx, events.Event{
|
||||
Kind: "agent_finish", At: today, Data: map[string]any{"tokens": 50},
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := s.InsertEvent(ctx, events.Event{
|
||||
Kind: "agent_finish", At: yesterday, Data: map[string]any{"tokens": 25},
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
byDay, err := s.TokensByDay(ctx, 14)
|
||||
if err != nil || len(byDay) != 2 {
|
||||
t.Fatalf("TokensByDay = (%+v, %v)", byDay, err)
|
||||
}
|
||||
// Newest day first.
|
||||
if byDay[0].Day != today.Format("2006-01-02") || byDay[0].Tokens != 150 {
|
||||
t.Fatalf("TokensByDay[0] = %+v", byDay[0])
|
||||
}
|
||||
if byDay[1].Day != yesterday.Format("2006-01-02") || byDay[1].Tokens != 25 {
|
||||
t.Fatalf("TokensByDay[1] = %+v", byDay[1])
|
||||
}
|
||||
|
||||
limited, err := s.TokensByDay(ctx, 1)
|
||||
if err != nil || len(limited) != 1 {
|
||||
t.Fatalf("TokensByDay with limit = (%+v, %v)", limited, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStageStats(t *testing.T) {
|
||||
s := openTest(t)
|
||||
ctx := context.Background()
|
||||
|
||||
@@ -1,111 +0,0 @@
|
||||
// Lifted from tau internal/agent/tools/stderr_redact.go
|
||||
// tau commit f5289ea3782c099339c2d26fe3af8ebcf42ba52d (2026-07-27).
|
||||
//
|
||||
// Mutations from upstream:
|
||||
// - package renamed tools -> builtin (archie-core already has an
|
||||
// internal/tools package holding the registry these are registered into).
|
||||
//
|
||||
// Refresh by diffing against that path at a newer tau commit. Do not
|
||||
// edit without recording the change above.
|
||||
package builtin
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"io"
|
||||
"log/slog"
|
||||
"regexp"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Redaction patterns per docs/specs/agents/03-wire-protocol.md (stderr
|
||||
// handling: Redaction) and 02-spawning-and-lifecycle.md (Redaction
|
||||
// contract). reBearerToken has no minimum length - the spec's own
|
||||
// redaction test requirement uses a 10-character example token
|
||||
// ("tok_abc123"), shorter than the {20,} it documents elsewhere for the
|
||||
// sk- pattern, so this errs toward redacting too much rather than missing
|
||||
// the documented test case.
|
||||
var (
|
||||
reBearerToken = regexp.MustCompile(`Bearer\s+[a-zA-Z0-9_\-.]+`)
|
||||
reSkKey = regexp.MustCompile(`sk-[a-zA-Z0-9]{20,}`)
|
||||
reEnvSecret = regexp.MustCompile(`(?i)\b([A-Za-z_]*(?:KEY|TOKEN|SECRET|PASSWORD)[A-Za-z_]*)=\S+`)
|
||||
)
|
||||
|
||||
// redactSecrets replaces known secret patterns in a single stderr line with
|
||||
// [REDACTED]. Order matters only for overlap avoidance; re-matching an
|
||||
// already-redacted "[REDACTED]" value is harmless (idempotent).
|
||||
func redactSecrets(line string) string {
|
||||
line = reBearerToken.ReplaceAllString(line, "Bearer [REDACTED]")
|
||||
line = reSkKey.ReplaceAllString(line, "[REDACTED]")
|
||||
line = reEnvSecret.ReplaceAllString(line, "$1=[REDACTED]")
|
||||
return line
|
||||
}
|
||||
|
||||
const (
|
||||
// stderrRateLimitBytesPerSec and stderrRateLimitWindow implement "4096
|
||||
// bytes per second, averaged over a 5-second window" - bursts within
|
||||
// the window are allowed (a full panic trace is captured), sustained
|
||||
// high-volume output past the window budget is truncated.
|
||||
stderrRateLimitBytesPerSec = 4096
|
||||
stderrRateLimitWindow = 5 * time.Second
|
||||
// stderrMaxCaptureBytes is the total per-instance capture cap; excess
|
||||
// is discarded (the pipe is still drained so a chatty child never
|
||||
// blocks on a full stderr pipe buffer).
|
||||
stderrMaxCaptureBytes = 64 * 1024
|
||||
)
|
||||
|
||||
// drainChildStderr reads r line-by-line, redacts known secret patterns,
|
||||
// rate-limits and caps total capture, and logs surviving lines at ERROR
|
||||
// level tagged with the child's instance ID. Never parsed for protocol
|
||||
// messages - stderr is diagnostic-only (see docs/specs/agents/
|
||||
// 03-wire-protocol.md). Blocks until r is exhausted (EOF on process exit);
|
||||
// callers run it in its own goroutine.
|
||||
func drainChildStderr(r io.Reader, instanceID string) {
|
||||
drainChildStderrWithClock(r, instanceID, time.Now)
|
||||
}
|
||||
|
||||
// drainChildStderrWithClock is drainChildStderr with an injectable clock,
|
||||
// so tests can advance the rate-limit window deterministically instead of
|
||||
// depending on real wall-clock time passing between reads.
|
||||
func drainChildStderrWithClock(r io.Reader, instanceID string, now func() time.Time) {
|
||||
scanner := bufio.NewScanner(r)
|
||||
scanner.Buffer(make([]byte, 4096), 1024*1024) // tolerate long lines without unbounded growth
|
||||
|
||||
windowBudget := stderrRateLimitBytesPerSec * int(stderrRateLimitWindow/time.Second)
|
||||
var (
|
||||
totalCaptured int
|
||||
capReported bool
|
||||
windowStart = now()
|
||||
windowBytes int
|
||||
rateLimitedThisWindow bool
|
||||
)
|
||||
|
||||
for scanner.Scan() {
|
||||
line := scanner.Text()
|
||||
lineBytes := len(line) + 1 // + newline, matching the byte-budget the spec describes
|
||||
|
||||
if totalCaptured >= stderrMaxCaptureBytes {
|
||||
if !capReported {
|
||||
slog.Error("[... stderr truncated: capture limit exceeded ...]", "instance_id", instanceID)
|
||||
capReported = true
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
if t := now(); t.Sub(windowStart) >= stderrRateLimitWindow {
|
||||
windowStart = t
|
||||
windowBytes = 0
|
||||
rateLimitedThisWindow = false
|
||||
}
|
||||
windowBytes += lineBytes
|
||||
if windowBytes > windowBudget {
|
||||
if !rateLimitedThisWindow {
|
||||
slog.Error("[... stderr truncated: rate limit exceeded ...]", "instance_id", instanceID)
|
||||
rateLimitedThisWindow = true
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
totalCaptured += lineBytes
|
||||
slog.Error(redactSecrets(line), "instance_id", instanceID)
|
||||
}
|
||||
}
|
||||
@@ -1,171 +0,0 @@
|
||||
package builtin
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log/slog"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
// --- G16: stderr redaction, rate limiting, capture cap ---
|
||||
|
||||
func TestRedactSecrets(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
in string
|
||||
want string
|
||||
}{
|
||||
{
|
||||
name: "api key env pattern",
|
||||
in: "TAU_API_KEY=sk-abc123testtesttesttest",
|
||||
want: "TAU_API_KEY=[REDACTED]",
|
||||
},
|
||||
{
|
||||
name: "bearer token, spec's exact example",
|
||||
in: "Authorization: Bearer tok_abc123",
|
||||
want: "Authorization: Bearer [REDACTED]",
|
||||
},
|
||||
{
|
||||
name: "bare sk- key",
|
||||
in: "leaked key: sk-abcdefghijklmnopqrstuvwxyz",
|
||||
want: "leaked key: [REDACTED]",
|
||||
},
|
||||
{
|
||||
name: "generic secret env var",
|
||||
in: "DATABASE_PASSWORD=hunter2",
|
||||
want: "DATABASE_PASSWORD=[REDACTED]",
|
||||
},
|
||||
{
|
||||
name: "generic token env var",
|
||||
in: "GITHUB_TOKEN=ghp_abcdefghijklmnop",
|
||||
want: "GITHUB_TOKEN=[REDACTED]",
|
||||
},
|
||||
{
|
||||
name: "no secret present",
|
||||
in: "starting build in /home/user/project",
|
||||
want: "starting build in /home/user/project",
|
||||
},
|
||||
{
|
||||
name: "ordinary key=value that is not sensitive",
|
||||
in: "BUILD_MODE=release",
|
||||
want: "BUILD_MODE=release",
|
||||
},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
got := redactSecrets(tc.in)
|
||||
if got != tc.want {
|
||||
t.Errorf("redactSecrets(%q) = %q, want %q", tc.in, got, tc.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestDrainChildStderr_RedactsBeforeLogging(t *testing.T) {
|
||||
var records []slog.Record
|
||||
orig := slog.Default()
|
||||
defer slog.SetDefault(orig)
|
||||
slog.SetDefault(slog.New(captureHandler{records: &records}))
|
||||
|
||||
r := strings.NewReader("TAU_API_KEY=sk-abc123testtesttesttest\n")
|
||||
drainChildStderr(r, "tau#test01")
|
||||
|
||||
if len(records) != 1 {
|
||||
t.Fatalf("expected 1 log record, got %d", len(records))
|
||||
}
|
||||
if strings.Contains(records[0].Message, "sk-abc123") {
|
||||
t.Errorf("secret leaked into log: %q", records[0].Message)
|
||||
}
|
||||
if !strings.Contains(records[0].Message, "[REDACTED]") {
|
||||
t.Errorf("expected redacted message, got %q", records[0].Message)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDrainChildStderr_CapsTotalCapture(t *testing.T) {
|
||||
var records []slog.Record
|
||||
orig := slog.Default()
|
||||
defer slog.SetDefault(orig)
|
||||
slog.SetDefault(slog.New(captureHandler{records: &records}))
|
||||
|
||||
// Each line is 100 bytes; write enough lines to exceed the 64KiB cap.
|
||||
// Uses a fake clock that jumps a full rate-limit window forward per
|
||||
// line, so the rate limiter never engages and only the capture cap is
|
||||
// under test - isolating it from TestDrainChildStderr_RateLimitsBurstInOneWindow.
|
||||
line := strings.Repeat("x", 99)
|
||||
var sb strings.Builder
|
||||
lineCount := (stderrMaxCaptureBytes / 100) + 50
|
||||
for range lineCount {
|
||||
sb.WriteString(line)
|
||||
sb.WriteByte('\n')
|
||||
}
|
||||
|
||||
fakeNow := time.Now()
|
||||
clock := func() time.Time {
|
||||
fakeNow = fakeNow.Add(stderrRateLimitWindow)
|
||||
return fakeNow
|
||||
}
|
||||
drainChildStderrWithClock(strings.NewReader(sb.String()), "tau#test02", clock)
|
||||
|
||||
var truncationMarkers int
|
||||
for _, rec := range records {
|
||||
if strings.Contains(rec.Message, "capture limit exceeded") {
|
||||
truncationMarkers++
|
||||
}
|
||||
}
|
||||
if truncationMarkers != 1 {
|
||||
t.Errorf("expected exactly 1 capture-limit truncation marker, got %d", truncationMarkers)
|
||||
}
|
||||
if len(records) >= lineCount {
|
||||
t.Errorf("expected fewer log records than input lines (cap should stop logging), got %d records for %d lines", len(records), lineCount)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDrainChildStderr_RateLimitsBurstInOneWindow(t *testing.T) {
|
||||
var records []slog.Record
|
||||
orig := slog.Default()
|
||||
defer slog.SetDefault(orig)
|
||||
slog.SetDefault(slog.New(captureHandler{records: &records}))
|
||||
|
||||
// Well over the 4096*5=20480 byte per-window budget, all within the
|
||||
// same instant (no real time passes reading from a strings.Reader).
|
||||
line := strings.Repeat("y", 999)
|
||||
var sb strings.Builder
|
||||
for range 50 { // ~50KB total, comfortably over the 20480 budget
|
||||
sb.WriteString(line)
|
||||
sb.WriteByte('\n')
|
||||
}
|
||||
|
||||
drainChildStderr(strings.NewReader(sb.String()), "tau#test03")
|
||||
|
||||
var rateLimitMarkers int
|
||||
for _, rec := range records {
|
||||
if strings.Contains(rec.Message, "rate limit exceeded") {
|
||||
rateLimitMarkers++
|
||||
}
|
||||
}
|
||||
if rateLimitMarkers != 1 {
|
||||
t.Errorf("expected exactly 1 rate-limit truncation marker, got %d", rateLimitMarkers)
|
||||
}
|
||||
if len(records) >= 50 {
|
||||
t.Errorf("expected rate limiting to suppress most of the 50 lines, got %d records", len(records))
|
||||
}
|
||||
}
|
||||
|
||||
// captureHandler is a minimal slog.Handler that records every Record it
|
||||
// receives, for asserting on log content without depending on slog's text
|
||||
// formatting.
|
||||
type captureHandler struct {
|
||||
records *[]slog.Record
|
||||
}
|
||||
|
||||
func (captureHandler) Enabled(context.Context, slog.Level) bool { return true }
|
||||
|
||||
func (h captureHandler) Handle(_ context.Context, r slog.Record) error {
|
||||
*h.records = append(*h.records, r)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h captureHandler) WithAttrs(_ []slog.Attr) slog.Handler { return h }
|
||||
|
||||
func (h captureHandler) WithGroup(_ string) slog.Handler { return h }
|
||||
Reference in new issue
Block a user