| 1 | package daemon |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "strings" |
| 6 | "testing" |
| 7 | "time" |
| 8 | |
| 9 | "github.com/FelineStateMachine/tinyrelay/internal/event" |
| 10 | "github.com/FelineStateMachine/tinyrelay/internal/mcp" |
| 11 | "github.com/FelineStateMachine/tinyrelay/internal/sites" |
| 12 | ) |
| 13 | |
| 14 | func TestSiteSnapshotStaysOutOfJobReads(t *testing.T) { |
| 15 | _, tenant := testTenant(t) |
| 16 | ctx := context.Background() |
| 17 | now := time.Now().Unix() |
| 18 | owner := tenant.Policy().Owner |
| 19 | paths := [][]string{{"path" , "/index.html" , strings.Repeat("a" , 64)}} |
| 20 | tags := append(paths, []string{"x" , sites.Aggregate(paths), "aggregate" }, []string{"a" , "15128:" + owner + ":" }) |
| 21 | snapshot := wikiPublish(t, tenant, wikiOwnerSecret, event.KIND_SITE_SNAPSHOT, now, "" , tags...) |
| 22 | job := wikiPublish(t, tenant, wikiOwnerSecret, 5001, now-1, "" , []string{"i" , "hello" , "text" }) |
| 23 | |
| 24 | result, err := tenant.browseJobs(ctx, owner, jobBrowseRequest{Limit: 1}) |
| 25 | if err != nil { |
| 26 | t.Fatal(err) |
| 27 | } |
| 28 | items := result.(map[string]any)["items" ].([]jobItem) |
| 29 | if len(items) != 1 || items[0].ID != job.ID { |
| 30 | t.Fatalf("job listing = %+v; want request %s" , items, job.ID) |
| 31 | } |
| 32 | if _, err := tenant.browseJob(ctx, owner, snapshot.ID); err == nil || !strings.Contains(err.Error(), "not found: job request" ) { |
| 33 | t.Fatalf("snapshot job read error = %v" , err) |
| 34 | } |
| 35 | if _, err := tenant.browseJob(ctx, owner, job.ID); err != nil { |
| 36 | t.Fatalf("job read: %v" , err) |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | func TestSiteSnapshotCannotBuildJobRequest(t *testing.T) { |
| 41 | if err := mcp.Validate(mcpJobKind, float64(event.KIND_SITE_SNAPSHOT)); err == nil { |
| 42 | t.Fatal("site snapshot kind accepted by the advertised job schema" ) |
| 43 | } |
| 44 | if _, err := mcpBuildJobRequest(mcp.Call{Arguments: map[string]any{"kind" : float64(event.KIND_SITE_SNAPSHOT)}}); err == nil { |
| 45 | t.Fatal("site snapshot kind accepted by the job request builder" ) |
| 46 | } |
| 47 | if err := mcpCheckJobRequest(event.Event{Kind: event.KIND_SITE_SNAPSHOT}); err == nil { |
| 48 | t.Fatal("site snapshot accepted by the signed job request checker" ) |
| 49 | } |
| 50 | } |