Files
archie/internal/infrastructure/configuration/artifacts_config_test.go
T
sam 0e6c6fc6d1 feat(artifacts): publish the completed PR review to the collaborative editor
Implements docs/prds/artifact-sender.md (Approved). archie-core now sends
generated artifacts to the offloaded.dev collaborative editor, whose
POST /api/artifacts route, bearer service token, PocketBase-backed
versions and idempotency semantics are the receiving contract.

- [artifacts] config section: base_url + token SecretRef with a
  token_env fallback naming WORKSPACE_INGEST_TOKEN. An empty base_url
  disables the sender entirely; a base_url with an unresolvable token
  disables it with a warning, because a missing credential disables a
  capability rather than stopping the daemon.
- internal/infrastructure/artifactsync: one-method Publish seam in the
  Courier posture, full source per publish (versions of record are
  snapshots), 503 retried three times with backoff, 401/400 surfaced
  immediately with the field reason, deterministic request ids
  (artifact:pr-review:<owner>/<repo>#<n>).
- ReviewReport gains a pure markdown renderer in internal/domain/workflow:
  summary, one subsection per finding with the failure scenario and
  disposition when present, verified properties as a checked-clean list.
- The daemon's PR reviewer publishes after a completed review when the
  sender is configured, records the editor deep link on the result, and
  degrades a failed publish to a log line -- publishing never fails the
  producing work.
2026-09-23 03:15:27 +10:00

53 lines
1.6 KiB
Go

package configuration
import (
"os"
"path/filepath"
"testing"
"github.com/samcharles93/archie-core/internal/config"
)
func TestArtifactsConfigDefaults(t *testing.T) {
path := filepath.Join(t.TempDir(), "config.toml")
contents := "bot_user = \"widget\"\n" +
"[forge]\ntype = \"gitea\"\nhost = \"https://git.example.test\"\ntoken_env = \"T\"\n"
if err := os.WriteFile(path, []byte(contents), 0o600); err != nil {
t.Fatal(err)
}
cfg, err := loadFile(path)
if err != nil {
t.Fatal(err)
}
if cfg.Artifacts.BaseURL != "" {
t.Errorf("BaseURL = %q, want empty so the sender stays disabled", cfg.Artifacts.BaseURL)
}
if cfg.Artifacts.TokenEnv != "WORKSPACE_INGEST_TOKEN" {
t.Errorf("TokenEnv = %q, want the documented fallback", cfg.Artifacts.TokenEnv)
}
}
func TestArtifactsConfigPreservesExplicitValues(t *testing.T) {
path := filepath.Join(t.TempDir(), "config.toml")
contents := "bot_user = \"widget\"\n" +
"[artifacts]\nbase_url = \"https://offloaded.dev\"\n" +
"token = { engine = \"env\", key = \"ARCHIE_GITHUB_TOKEN\" }\n" +
"token_env = \"OTHER_TOKEN\"\n"
if err := os.WriteFile(path, []byte(contents), 0o600); err != nil {
t.Fatal(err)
}
cfg, err := loadFile(path)
if err != nil {
t.Fatal(err)
}
if cfg.Artifacts.BaseURL != "https://offloaded.dev" {
t.Errorf("BaseURL = %q, want the explicit value", cfg.Artifacts.BaseURL)
}
if want := (config.SecretRef{Engine: "env", Key: "ARCHIE_GITHUB_TOKEN"}); cfg.Artifacts.Token != want {
t.Errorf("Token = %+v, want %+v", cfg.Artifacts.Token, want)
}
if cfg.Artifacts.TokenEnv != "OTHER_TOKEN" {
t.Errorf("TokenEnv = %q, want the explicit value", cfg.Artifacts.TokenEnv)
}
}