Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix: pre-landing review fixes

garrytandbfd182d0ecc
diff --git a/src/commands/import.ts b/src/commands/import.ts
index 22db94499f..282438c061 100644
--- a/src/commands/import.ts
+++ b/src/commands/import.ts
@@ -270,7 +270,7 @@ export async function runImport(
sourceId?: string;
managedBookmark?: boolean;
/** Paths the caller keeps out of this run (#5988 holds, #8620 reserved skill paths); skipped without importing, not failures. */
- heldPaths?: ReadonlySet<string>;
+ heldPaths?: Pick<ReadonlySet<string>, 'has'>;
/** #5988: each file's outcome (a throw arrives as `{ status: 'error', error }`); `'held'` = the caller held it, not a failure. */
onFileResult?: ImportFileResultCallback;
/**
diff --git a/src/commands/sync/plain-directory.ts b/src/commands/sync/plain-directory.ts
index 2d0402a800..f333b56303 100644
--- a/src/commands/sync/plain-directory.ts
+++ b/src/commands/sync/plain-directory.ts
@@ -69,19 +69,15 @@ export async function performPlainDirectorySync(engine: BrainEngine, opts: SyncO
const empty = { fromCommit: null, toCommit: '', modified: 0, deleted: 0, renamed: 0, chunksCreated: 0, embedded: 0, pagesAffected: [] };
serr(`[sync] ${root} is a plain directory, not a Git checkout, so sync imports its files into source ${sourceId}; a file removed from it keeps its page.`);
const { runImport, collectSyncableFiles } = await import('../import.ts');
- const files = opts.dryRun || managed
- ? collectSyncableFiles(root, { strategy: opts.strategy ?? 'markdown', includeHidden: opts.includeHidden, metafilePages: await readMetafilePagesMode(engine) })
- .map(abs => relative(root, abs)).filter(path => !matchesAnyGlob(path, exclude))
- : [];
- const reserved = new Set(managed ? files.filter(isReservedSkillBundlePath) : []);
if (opts.dryRun) {
- slog(`Plain-directory dry run: ${files.length - reserved.size} file(s) would be imported from ${root}.`);
- return { ...empty, status: 'dry_run', added: files.length - reserved.size };
+ const files = collectSyncableFiles(root, { strategy: opts.strategy ?? 'markdown', includeHidden: opts.includeHidden, metafilePages: await readMetafilePagesMode(engine) })
+ .map(abs => relative(root, abs)).filter(path => !matchesAnyGlob(path, exclude) && !(managed && isReservedSkillBundlePath(path)));
+ slog(`Plain-directory dry run: ${files.length} file(s) would be imported from ${root}.`);
+ return { ...empty, status: 'dry_run', added: files.length };
}
- if (reserved.size) serr(`[sync] Left ${reserved.size} reserved skill file(s) (skills/, skillpack.json) to the shared skill publisher; import never publishes skills.`);
const keyless = loadConfig()?.embedding_disabled === true || (await engine.getConfig('embedding_disabled')) === 'true';
const result = await runImport(engine, [root, ...(opts.noEmbed || keyless ? ['--no-embed'] : [])],
- { signal: opts.signal, sourceId, strategy: opts.strategy, exclude, includeHidden: opts.includeHidden, heldPaths: reserved });
+ { signal: opts.signal, sourceId, strategy: opts.strategy, exclude, includeHidden: opts.includeHidden, ...(managed ? { heldPaths: { has: isReservedSkillBundlePath } } : {}) });
if (result.errors > 0) return { ...empty, status: 'blocked_by_failures', added: result.imported, chunksCreated: result.chunksCreated, failedFiles: result.errors };
// A managed brain fences source checkpoints to coordinated writers; the classic import stamps last_sync_at itself.
if (managed) {
diff --git a/test/sync-plain-directory-skillpack-8620.test.ts b/test/sync-plain-directory-skillpack-8620.test.ts
index 293d77e883..ade9c7a8f3 100644
--- a/test/sync-plain-directory-skillpack-8620.test.ts
+++ b/test/sync-plain-directory-skillpack-8620.test.ts
@@ -3,11 +3,13 @@
* plus skills/<name>/SKILL.md). Plain-directory sync must leave those reserved paths to the shared skill publisher, the
* way managed Git sync discovery does, instead of handing them to the importer, which refuses each one with
* skill_bundle_required and blocks the source for good.
- * Fails when: the sync after the export ends blocked_by_failures, the dry run counts the pack's files, or the sync
- * writes the pack into pages or the shared skill catalog.
+ * Fails when: the sync after the export ends blocked_by_failures, the dry run counts the pack's files, the sync
+ * writes the pack into pages or the shared skill catalog, or a skill the publisher writes while the sync walks the
+ * directory reaches the importer and blocks the run.
*/
-import { afterAll, beforeAll, expect, test } from 'bun:test';
-import { existsSync, mkdtempSync, rmSync } from 'node:fs';
+import { afterAll, beforeAll, expect, spyOn, test } from 'bun:test';
+import * as fs from 'node:fs';
+import { existsSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
import { join } from 'node:path';
import { tmpdir } from 'node:os';
import { PGLiteEngine } from '../src/core/pglite-engine.ts';
@@ -53,6 +55,24 @@ test('a plain directory holding the exported memory pack syncs, and the dry run
expect(source?.last_sync_at).not.toBeNull();
expect(await engine.executeRaw("SELECT slug FROM pages WHERE source_id='default' AND (slug ILIKE 'skills/%' OR slug ILIKE 'skillpack%')")).toEqual([]);
expect(await catalog()).toEqual(before);
+
+ const realReaddir = fs.readdirSync;
+ let published = false;
+ const readdir = spyOn(fs, 'readdirSync').mockImplementation(((path: fs.PathLike, ...rest: unknown[]) => {
+ const entries = (realReaddir as (...args: unknown[]) => unknown)(path, ...rest);
+ if (!published && String(path) === fs.realpathSync(root) && new Error().stack?.includes('collectSyncableFiles')) {
+ published = true;
+ mkdirSync(join(root, 'team-example', 'skills', 'late-example'), { recursive: true });
+ writeFileSync(join(root, 'team-example', 'skills', 'late-example', 'SKILL.md'), '---\nname: late-example\n---\n\nPublished while the sync runs.\n');
+ }
+ return entries;
+ }) as typeof fs.readdirSync);
+ try {
+ expect(await performSync(engine, { sourceId: 'default', noPull: true, noEmbed: true })).toMatchObject({ status: 'synced' });
+ } finally { readdir.mockRestore(); }
+ expect(published).toBe(true);
+ expect(await performSync(engine, { sourceId: 'default', noPull: true, noEmbed: true })).toMatchObject({ status: 'synced' });
+ expect(await engine.executeRaw("SELECT slug FROM pages WHERE source_id='default' AND (slug ILIKE 'skills/%' OR slug ILIKE '%/skills/%')")).toEqual([]);
});
} finally { rmSync(home, { recursive: true, force: true }); }
}, 180_000);