- ApprovalService (core/app/approval.go) + ApprovalRepo (postgres adapter) with
full decide transaction: HMAC token verify, approval flip, execution un-gate,
session-scoped window keys (+session suffix matching GovernanceStore gate),
nomos session flip, audit+event on failure abort. httpapi DecideApproval now
a thin presenter delegating to the service. ListPending payload format fixed
(json.Unmarshal not raw-wrap).
- execlog folded into postgres adapter: internal/execlog deleted, NewExecutionLog
/ ReadExecutionLog live in the db package, callers updated (mcp, httpapi).
- execworker poller over ExecutionService.DispatchQueued: advisory lock leak
fixed (defer/recover per execution), correlation_id preserved via Finalize
event emission (ExecRunRepo.Finalize now emits execution.{status} with
correlation_id from the row).
- Phase 8 session export-rename completed: Store, New, and all 53 methods
exported; cmd/nomos/ agent.go fixed to use session.PendingContinuation etc.
- Coverage gates: ExecutionService.Submit 93.1%, PolicyService.Decide 100%.
- Plans index updated, VERSION bumped to 0.36.0.
129 lines
4.3 KiB
Go
129 lines
4.3 KiB
Go
package assent
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestIsAssent_Positive(t *testing.T) {
|
|
cases := []string{
|
|
"go ahead", "Go ahead.", "yes", "Yes!", "yeah", "yep", "do it",
|
|
"proceed", "approve", "ship it", "sounds good", "lgtm", "please do",
|
|
"ok go ahead and run it",
|
|
}
|
|
for _, c := range cases {
|
|
if !IsAssent(c) {
|
|
t.Errorf("IsAssent(%q) = false, want true", c)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestIsAssent_Negative(t *testing.T) {
|
|
cases := []string{
|
|
"no", "no, don't", "wait", "hold on", "not yet", "cancel that",
|
|
"nevermind", "what's the plan for tomorrow?", "how many CPUs does strong have?",
|
|
"maybe later", "",
|
|
}
|
|
for _, c := range cases {
|
|
if IsAssent(c) {
|
|
t.Errorf("IsAssent(%q) = true, want false", c)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestIsAssent_NegationBeatsAssentWord(t *testing.T) {
|
|
// Contains "yes" as a substring pattern risk word but is clearly not
|
|
// assent — negation must win.
|
|
cases := []string{
|
|
"no, don't do it yet",
|
|
"wait, not yet please",
|
|
}
|
|
for _, c := range cases {
|
|
if IsAssent(c) {
|
|
t.Errorf("IsAssent(%q) = true, want false (negation should block)", c)
|
|
}
|
|
}
|
|
}
|
|
|
|
// TestIsAssent_WholeWordBoundary regression-tests a real false positive found
|
|
// live: the old substring check matched "yes" inside "yesterday" (and would
|
|
// equally match "confirm" inside "confirmed"/"unconfirmed" for
|
|
// IsTypedConfirmation below) because only negation used a word-boundary
|
|
// check — assent/confirm words used a bare strings.Contains. Confirmed via a
|
|
// throwaway probe before being fixed; kept here permanently so a future
|
|
// change can't silently reintroduce it.
|
|
func TestIsAssent_WholeWordBoundary(t *testing.T) {
|
|
cases := []string{
|
|
"not sure, maybe yesterday's logs show something useful",
|
|
"my eyesight isn't great, what does that say",
|
|
}
|
|
for _, c := range cases {
|
|
if IsAssent(c) {
|
|
t.Errorf("IsAssent(%q) = true, want false (word-boundary: 'yes' must not match inside 'yesterday'/'eyesight')", c)
|
|
}
|
|
}
|
|
}
|
|
|
|
// TestIsTypedConfirmation_ContractedNegation regression-tests the other real
|
|
// false positive: IsTypedConfirmation gates DESTRUCTIVE actions, and
|
|
// "confirm" matching inside "confirmed" combined with contracted negatives
|
|
// ("haven't") not being in negationWords meant a message that explicitly
|
|
// says the operator has NOT confirmed something could read as confirming it.
|
|
func TestIsTypedConfirmation_ContractedNegation(t *testing.T) {
|
|
cases := []string{
|
|
"I haven't confirmed anything yet, let me think",
|
|
"that isn't confirmed on my end",
|
|
"we can't confirm that until tomorrow",
|
|
}
|
|
for _, c := range cases {
|
|
if IsTypedConfirmation(c) {
|
|
t.Errorf("IsTypedConfirmation(%q) = true, want false (contracted negation should block)", c)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestIsTypedConfirmation(t *testing.T) {
|
|
positive := []string{
|
|
"I confirm destroy 135 in strong",
|
|
"confirm",
|
|
"Confirmed.",
|
|
"yes I confirm",
|
|
}
|
|
for _, c := range positive {
|
|
if !IsTypedConfirmation(c) {
|
|
t.Errorf("IsTypedConfirmation(%q) = false, want true", c)
|
|
}
|
|
}
|
|
negative := []string{
|
|
"yes", "go ahead", "do it", "proceed", "lgtm", // loose assent must NOT satisfy this
|
|
"no, don't confirm yet", "wait", "",
|
|
}
|
|
for _, c := range negative {
|
|
if IsTypedConfirmation(c) {
|
|
t.Errorf("IsTypedConfirmation(%q) = true, want false (only explicit confirm should pass)", c)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestExtractPendingApprovals(t *testing.T) {
|
|
got := ExtractPendingApprovals([]string{
|
|
"run on host:strong requires approval (risk: config_mutation) - execution 019f4930-e22b-7c47-8c6e-715dcd59df19 queued. Present the command...",
|
|
"some unrelated read-only result, no approval here",
|
|
"run on lxc:caddy requires approval (risk: destructive) - execution 019f4931-aaaa-7c47-8c6e-715dcd59df20 queued. This is classified DESTRUCTIVE - flag that clearly.",
|
|
})
|
|
if len(got) != 2 {
|
|
t.Fatalf("expected 2 pending approvals, got %d", len(got))
|
|
}
|
|
if got[0].ExecID != "019f4930-e22b-7c47-8c6e-715dcd59df19" || got[0].Destructive {
|
|
t.Errorf("first approval: ExecID=%s Destructive=%v", got[0].ExecID, got[0].Destructive)
|
|
}
|
|
if got[1].ExecID != "019f4931-aaaa-7c47-8c6e-715dcd59df20" || !got[1].Destructive {
|
|
t.Errorf("second approval should be flagged destructive: %+v", got[1])
|
|
}
|
|
}
|
|
|
|
func TestExtractPendingApprovals_NoneWhenNoneQueued(t *testing.T) {
|
|
if got := ExtractPendingApprovals(nil); len(got) != 0 {
|
|
t.Errorf("expected 0, got %d", len(got))
|
|
}
|
|
}
|