testing: bootstrap UI, agent reliability, NS-01..04 + alert username
Smoothes the rough edges that came up exercising a live deployment.
First-run bootstrap UI: /bootstrap renders a username + password form
that uses the in-memory token directly (operator no longer copies it
out of the log); /login redirects there while bootstrap is available.
Agent reliability: failJob synthetic envelopes so command.run early
returns no longer hang the server-side job; runtime probe of restic
restore --help drives --no-ownership instead of version sniffing
(0.18.x had it removed). Server unit re-shaped: ProtectSystem=full
plus ReadWritePaths=/etc/restic-manager, no ProtectHome — restore
can now write anywhere a user might want.
Restore wizard: default target is /root/rm-restore/<job-id>/ with
clearer help text. Re-init confirm input uses .field (was .input,
which doesn't exist — text was invisible).
NS-01 host delete: store DeleteHost, admin-band /hosts/{id}/delete
with hostname-confirm danger zone, audit, FK cascade, live WS close.
NS-02 enrollment-token recovery: outstanding-tokens panel on
/hosts/new, regenerate (preserves attachments) and revoke handlers
+ audit, store-level ListOutstandingEnrollmentTokens and
DeleteEnrollmentToken.
NS-03 repo init / probe surface: migration 0020 adds
hosts.repo_status + repo_status_error; WS handler projects every
init job's outcome onto the host row (idempotent already-initialised
collapses to ready); creds-save resets status and dispatches a fresh
probe; /hosts/{id}/repo/probe retry endpoint with banner.
NS-04 dashboard live + sort + filter: query-string filter
(q/status/repo_status/tag/sort/dir), 5s htmx live poll mirroring the
alerts pattern with a localStorage live toggle, sortable column
headers, filter row + clear.
Alerts page: ack'd-by line resolves user_id ULID to username.
Compose.yaml ignored — host-specific.
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
package ws
|
||||
|
||||
import "testing"
|
||||
|
||||
// TestRepoStatusFromInit covers the NS-03 status projection: success,
|
||||
// the "already initialised" idempotency cases (treated as success),
|
||||
// and arbitrary failures (preserved into the host row's error field).
|
||||
func TestRepoStatusFromInit(t *testing.T) {
|
||||
t.Parallel()
|
||||
cases := []struct {
|
||||
name string
|
||||
jobStatus string
|
||||
errMsg string
|
||||
want string
|
||||
wantErr string
|
||||
}{
|
||||
{"succeeded", "succeeded", "", "ready", ""},
|
||||
{"already initialised (en-GB)", "failed", "Fatal: create repository at rest:http://r failed: server response unexpected: config file already exists", "ready", ""},
|
||||
{"already initialised (en-US spelling)", "failed", "boom: already init" + "ialized", "ready", ""},
|
||||
{"bad creds", "failed", "Fatal: server response unexpected: 401 Unauthorised", "init_failed", "Fatal: server response unexpected: 401 Unauthorised"},
|
||||
{"network", "failed", "dial tcp 192.168.0.99:8000: i/o timeout", "init_failed", "dial tcp 192.168.0.99:8000: i/o timeout"},
|
||||
}
|
||||
for _, c := range cases {
|
||||
c := c
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
gotStatus, gotErr := repoStatusFromInit(c.jobStatus, c.errMsg)
|
||||
if gotStatus != c.want {
|
||||
t.Errorf("status: got %q, want %q", gotStatus, c.want)
|
||||
}
|
||||
if gotErr != c.wantErr {
|
||||
t.Errorf("err: got %q, want %q", gotErr, c.wantErr)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestRepoStatusFromInitTruncates: huge stack traces from the agent
|
||||
// should not bloat the hosts row. Cap at 512 + ellipsis.
|
||||
func TestRepoStatusFromInitTruncates(t *testing.T) {
|
||||
t.Parallel()
|
||||
long := make([]byte, 1024)
|
||||
for i := range long {
|
||||
long[i] = 'x'
|
||||
}
|
||||
_, got := repoStatusFromInit("failed", string(long))
|
||||
if len(got) > 520 {
|
||||
t.Errorf("err length: got %d, want <= 520 (512 + ellipsis runes)", len(got))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user