feat(brain): audit-log every tools/call; server-owned write provenance (#147)
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>
This commit was merged in pull request #147.
This commit is contained in:
@@ -104,6 +104,10 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
// caller may have tried to put in the body.
|
||||
in.Context.Principal = principal
|
||||
in.Context.Origin = h.resolver.Resolve(principal, viaStatic)
|
||||
in.Context.AuthPath = "jwt"
|
||||
if viaStatic {
|
||||
in.Context.AuthPath = "static"
|
||||
}
|
||||
|
||||
rec, err := h.svc.Capture(r.Context(), in)
|
||||
switch {
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
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)
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user