test(rules-core): isolate sisyphus deprecation warning assertion

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
YeonGyu-Kim
2026-05-20 13:19:33 +09:00
parent 53ddc470e3
commit 12aaff28b5
2 changed files with 21 additions and 8 deletions
+11 -1
View File
@@ -10,6 +10,7 @@ import { log } from "../../../src/shared/logger";
const SISYPHUS_DEPRECATION_MESSAGE = "[rules] .sisyphus/rules is deprecated and will be removed in v4.3.0; migrate to .omo/rules";
const SISYPHUS_LEGACY_RULE_SOURCES: ReadonlySet<RuleSource> = new Set([".sisyphus/rules", "~/.sisyphus/rules"]);
const warnedSisyphusRuleDirectories = new Set<string>();
let logSisyphusRuleDeprecation: typeof log = log;
export function findRuleFiles(
projectRoot: string | null,
@@ -148,12 +149,21 @@ function warnSisyphusRuleDeprecation(source: RuleSource, path: string): void {
const warningKey = dirname(path);
if (warnedSisyphusRuleDirectories.has(warningKey)) return;
warnedSisyphusRuleDirectories.add(warningKey);
log(SISYPHUS_DEPRECATION_MESSAGE, {
logSisyphusRuleDeprecation(SISYPHUS_DEPRECATION_MESSAGE, {
event: "rules-sisyphus-deprecated",
path,
});
}
export function _setSisyphusRuleDeprecationLoggerForTesting(logger: typeof log): void {
logSisyphusRuleDeprecation = logger;
}
export function _resetSisyphusRuleDeprecationWarningStateForTesting(): void {
warnedSisyphusRuleDirectories.clear();
logSisyphusRuleDeprecation = log;
}
function validFileRealPath(filePath: string): string | null {
if (!existsSync(filePath)) return null;
try {
+10 -7
View File
@@ -1,7 +1,7 @@
import { mkdirSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { afterEach, describe, expect, it, mock, spyOn } from "bun:test";
import { afterEach, describe, expect, it } from "bun:test";
import {
clearProjectRootCache,
@@ -13,7 +13,7 @@ import {
parseRuleFrontmatter,
shouldApplyRule,
} from "./index";
import * as logger from "../../../src/shared/logger";
import { _resetSisyphusRuleDeprecationWarningStateForTesting, _setSisyphusRuleDeprecationLoggerForTesting } from "./finder";
let testRoot: string | null = null;
@@ -26,7 +26,7 @@ function createTestRoot(name: string): string {
}
afterEach(() => {
mock.restore();
_resetSisyphusRuleDeprecationWarningStateForTesting();
if (testRoot) {
rmSync(testRoot, { recursive: true, force: true });
testRoot = null;
@@ -97,17 +97,20 @@ describe("rules-core", () => {
mkdirSync(join(root, ".sisyphus", "rules"), { recursive: true });
mkdirSync(join(root, "src"), { recursive: true });
writeFileSync(legacyRulePath, "legacy");
const logSpy = spyOn(logger, "log").mockImplementation(() => {});
const warnings: Array<{ readonly message: string; readonly data: unknown }> = [];
_setSisyphusRuleDeprecationLoggerForTesting((message, data) => {
warnings.push({ message, data });
});
// when
findRuleFiles(root, root, join(root, "src", "index.ts"));
findRuleFiles(root, root, join(root, "src", "index.ts"));
const warnings = logSpy.mock.calls.filter(
([message, data]) => message === SISYPHUS_DEPRECATION_MESSAGE && isSisyphusDeprecationData(data, legacyRulePath),
const deprecationWarnings = warnings.filter(
({ message, data }) => message === SISYPHUS_DEPRECATION_MESSAGE && isSisyphusDeprecationData(data, legacyRulePath),
);
// then
expect(warnings).toHaveLength(1);
expect(deprecationWarnings).toHaveLength(1);
});
it("#given a workspace directory has no project marker (no .git, no package.json, etc.) AND contains .omo/rules/ #when findRuleFiles is called #then the .omo/rules/ files are still discovered", () => {