Skip to content

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

:test_tube: Correct prompt assertions and synchronize window loading tests

Daniel63303482a5bb
diff --git a/app/tests/mainWindowLoading.test.js b/app/tests/mainWindowLoading.test.js
index 6b92e70768..ef937894e0 100644
--- a/app/tests/mainWindowLoading.test.js
+++ b/app/tests/mainWindowLoading.test.js
@@ -137,6 +137,7 @@ const runCase = async (sources, options) => {
if (process.versions.electron && process.type === "browser") {
const {app, BrowserWindow} = require("electron");
const {createServer} = require("node:http");
+ const {once} = require("node:events");
app.on("window-all-closed", () => {});
app.disableHardwareAcceleration();
app.setPath("userData", process.argv[2]);
@@ -158,7 +159,11 @@ if (process.versions.electron && process.type === "browser") {
const pending = [];
const server = createServer((request, response) => {
const pathname = new URL(request.url, "http://localhost").pathname;
- if (pathname === "/theme.css") { pending.push(response); return; }
+ if (pathname === "/theme.css") {
+ pending.push(response);
+ server.emit("theme-request");
+ return;
+ }
if (pathname === "/base.css") {
response.setHeader("Content-Type", "text/css");
response.end(css);
@@ -180,7 +185,12 @@ if (process.versions.electron && process.type === "browser") {
win = new BrowserWindow({show: false, width: 640, height: 480,
webPreferences: {nodeIntegration: true, contextIsolation: false, offscreen: true}});
await win.loadURL(`http://127.0.0.1:${server.address().port}/stage/build/${options.browser ? "desktop" : "app"}/index.html`);
- await win.webContents.executeJavaScript(`(${runCase.toString()})(${JSON.stringify(sources)}, ${JSON.stringify(options)})`);
+ // 渲染进程插入样式后,请求仍需异步到达主进程中的测试服务器。
+ const themeRequested = once(server, "theme-request", {signal: AbortSignal.timeout(10000)});
+ await Promise.all([
+ win.webContents.executeJavaScript(`(${runCase.toString()})(${JSON.stringify(sources)}, ${JSON.stringify(options)})`),
+ themeRequested,
+ ]);
assert.equal(pending.length, 1);
pending.pop().writeHead(200, {"Content-Type": "text/css"}).end(
":root{--b3-font-size:14px;--b3-toolbar-left-mac:5px;--b3-body-background:#234567;--b3-theme-background:#234567;}");
diff --git a/kernel/agent/prompt_test.go b/kernel/agent/prompt_test.go
index 8babfb4b00..e383eaaad5 100644
--- a/kernel/agent/prompt_test.go
+++ b/kernel/agent/prompt_test.go
@@ -103,12 +103,23 @@ func TestSystemPromptPreservesNativeStructure(t *testing.T) {
{registrations: map[string]*capabilityRegistration{}},
} {
prompt := filterSystemPromptByCapabilities(systemPrompt, capabilities)
- if !strings.Contains(prompt, "preserve existing structure, block IDs, and metadata") {
+ var nativeStructure string
+ for _, line := range strings.Split(prompt, "\n") {
+ if strings.HasPrefix(line, "- Native structured blocks:") {
+ nativeStructure = line
+ break
+ }
+ }
+ if !strings.Contains(nativeStructure, "preserve existing structure, block IDs, and metadata") {
t.Fatal("native structure protection was removed by capability filtering")
}
+ // parentID 同时用于文档寻址,只在原生块结构说明中排除该参数细节。
+ if strings.Contains(nativeStructure, "parentID") {
+ t.Fatal("block-specific parentID detail belongs in the tool description, not the native structure instruction")
+ }
for _, detail := range []string{
"NodeTabs", "NodeTabItem", "NodeMindmap", "NodeMindmapItem", "::: tabs", "@tab", "tabs-position", "tabs-active-id",
- "{{{col", "{{{row", "first paragraph", "second paragraph", "data-sb-layout", "NodeList", "previousID", "parentID",
+ "{{{col", "{{{row", "first paragraph", "second paragraph", "data-sb-layout", "NodeList", "previousID",
"((<blockID>", "[[<blockID>]]", `data-type="text`, `data-type="u"`, `data-type="sup"`, `data-type="sub"`,
`data-type="kbd"`, "font-size", "font-weight", "<ruby>", "NodeHTMLBlock", "NodeCodeBlock",
} {
@@ -119,6 +130,21 @@ func TestSystemPromptPreservesNativeStructure(t *testing.T) {
}
}
+func TestSystemPromptDocumentsStructuredDocumentAddressing(t *testing.T) {
+ for _, instruction := range []string{
+ "Never split an hPath or use it to recover identity",
+ "Document create/list/move and inbox.convert use notebook + parentID",
+ `parentID="" explicitly selects the notebook root`,
+ "returns legacyPathUnsupported in structured-title notebooks",
+ "document.list (notebook + parentID, omitted parentID lists the notebook root)",
+ "document.create (notebook + parentID + independent literal title)",
+ } {
+ if !strings.Contains(systemPrompt, instruction) {
+ t.Fatalf("missing structured document addressing instruction %q", instruction)
+ }
+ }
+}
+
func TestSystemPromptOmitsUnavailableSkillInstructions(t *testing.T) {
capabilities := &capabilitySet{registrations: map[string]*capabilityRegistration{}}
prompt := buildSystemPrompt("English", capabilities)