Closes #144 (audit line per tools/call) and #145 (origin/written_by stamped on every model-reachable write, surfaced in brain_query/brain_get). Passed pr-gatekeeper after four rounds of adversarial review, verified by execution: #147 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Mathias <mthbqv@gmail.com>
52 lines
2.1 KiB
Go
52 lines
2.1 KiB
Go
package capturehttp_test
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/mathiasbq/hyperguild/ingestion/internal/audit"
|
|
"github.com/mathiasbq/hyperguild/ingestion/internal/brainstore"
|
|
"github.com/mathiasbq/hyperguild/ingestion/internal/capture"
|
|
"github.com/mathiasbq/hyperguild/ingestion/internal/capturehttp"
|
|
"github.com/mathiasbq/hyperguild/ingestion/internal/classification"
|
|
)
|
|
|
|
// The REST capture door derives AuthPath itself (hyperguild#145); a body
|
|
// field cannot set it, and static vs JWT are told apart.
|
|
func TestRESTCaptureStampsAuthPathFromAuthentication(t *testing.T) {
|
|
for _, tc := range []struct {
|
|
name, authz, wantOrigin, wantBy string
|
|
v capturehttp.Validator
|
|
sovereign []string
|
|
}{
|
|
{"static", "Bearer " + staticTok, "origin: static\n", "written_by: local-cli\n", nil, nil},
|
|
{"jwt", "Bearer jwt", "origin: jwt\n", "written_by: koala-cli\n", fakeValidator{subject: "koala-cli"}, []string{"koala-cli"}},
|
|
} {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
brainDir := t.TempDir()
|
|
cfg, err := classification.Load(t.TempDir())
|
|
require.NoError(t, err)
|
|
svc := capture.NewService(brainstore.New(brainDir), fakeTracker{}, cfg, audit.NewSlogSink(nil))
|
|
h := capturehttp.New(svc, tc.v, staticTok, "local-cli", capturehttp.NewOriginResolver(tc.sovereign))
|
|
rr := do(t, h, tc.authz, map[string]any{
|
|
"context": map[string]any{
|
|
"harness": "claude-code", "actor": "mathias", "classification": "internal",
|
|
"AuthPath": "static", "auth_path": "static", "principal": "local-cli",
|
|
},
|
|
"insights": []map[string]any{{"text": "rest provenance probe", "wing": "hyperguild", "hall": "facts"}},
|
|
})
|
|
require.Equal(t, 200, rr.Code, rr.Body.String())
|
|
matches, _ := filepath.Glob(filepath.Join(brainDir, "wiki/hyperguild/facts/*.md"))
|
|
require.Len(t, matches, 1)
|
|
b, err := os.ReadFile(matches[0])
|
|
require.NoError(t, err)
|
|
assert.Contains(t, string(b), tc.wantOrigin)
|
|
assert.Contains(t, string(b), tc.wantBy)
|
|
})
|
|
}
|
|
}
|