Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

1.4 KB
Raw Blame
// SiYuan - https://github.com/siyuan-note/siyuan
// Copyright (c) 2020-present, b3log.org
// SPDX-License-Identifier: AGPL-3.0-or-later

package agent

import (
	"testing"

	"github.com/siyuan-note/siyuan/kernel/conf"
	"github.com/siyuan-note/siyuan/kernel/mcp/tools"
	kernelModel "github.com/siyuan-note/siyuan/kernel/model"
)

func TestSnippetWritesAlwaysRequireExplicitConfirmation(t *testing.T) {
	previous := kernelModel.Conf
	kernelModel.Conf = kernelModel.NewAppConf()
	kernelModel.Conf.AI.Store(conf.NewAI())
	t.Cleanup(func() { kernelModel.Conf = previous })
	registration := &capabilityRegistration{ID: "native/backend/snippet", ModelName: "snippet", Source: "native", Runtime: "kernel", Tool: tools.SnippetTool}
	kernelModel.Conf.AI.Load().Agent.ApprovalPolicy.Overrides[registration.ID] = &conf.CapabilityApproval{Default: conf.ApprovalDecisionAllow}
	for _, action := range []string{"create", "update", "replace", "enable", "disable", "remove"} {
		for _, session := range []bool{false, true} {
			required, forced := capabilityConfirmRequirement(registration, action, nil, session, map[string]bool{"*": true})
			if !required || !forced {
				t.Fatalf("%s escaped confirmation (session=%v)", action, session)
			}
		}
	}
	for _, action := range []string{"list", "get"} {
		if required, _ := capabilityConfirmRequirement(registration, action, nil, false, nil); required {
			t.Fatalf("read %s unexpectedly requires confirmation", action)
		}
	}
}