From 12aaff28b58b3a18a21ff2c47cc23982f53ebb92 Mon Sep 17 00:00:00 2001 From: YeonGyu-Kim Date: Wed, 20 May 2026 13:19:33 +0900 Subject: [PATCH] test(rules-core): isolate sisyphus deprecation warning assertion Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus --- packages/rules-core/src/finder.ts | 12 +++++++++++- packages/rules-core/src/index.test.ts | 17 ++++++++++------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/packages/rules-core/src/finder.ts b/packages/rules-core/src/finder.ts index 1dcd46a92..71bd12205 100644 --- a/packages/rules-core/src/finder.ts +++ b/packages/rules-core/src/finder.ts @@ -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 = new Set([".sisyphus/rules", "~/.sisyphus/rules"]); const warnedSisyphusRuleDirectories = new Set(); +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 { diff --git a/packages/rules-core/src/index.test.ts b/packages/rules-core/src/index.test.ts index 4448893d5..bec5438e2 100644 --- a/packages/rules-core/src/index.test.ts +++ b/packages/rules-core/src/index.test.ts @@ -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", () => {