@crewhaus/rules-engine 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +6 -11
  2. package/src/index.test.ts +45 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crewhaus/rules-engine",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "type": "module",
5
5
  "description": "Cross-cutting (Track 10) — reads multi-language rule packs from rules/{common,typescript,python,...} and injects them as system-prompt prefixes. Source: ECC reference repo.",
6
6
  "main": "src/index.ts",
@@ -12,13 +12,13 @@
12
12
  "test": "bun test src"
13
13
  },
14
14
  "dependencies": {
15
- "@crewhaus/errors": "0.1.1"
15
+ "@crewhaus/errors": "0.1.3"
16
16
  },
17
17
  "license": "Apache-2.0",
18
18
  "author": {
19
19
  "name": "Max Meier",
20
- "email": "max@studiomax.io",
21
- "url": "https://studiomax.io"
20
+ "email": "max@crewhaus.ai",
21
+ "url": "https://crewhaus.ai"
22
22
  },
23
23
  "repository": {
24
24
  "type": "git",
@@ -30,12 +30,7 @@
30
30
  "url": "https://github.com/crewhaus/factory/issues"
31
31
  },
32
32
  "publishConfig": {
33
- "access": "restricted"
33
+ "access": "public"
34
34
  },
35
- "files": [
36
- "src",
37
- "README.md",
38
- "LICENSE",
39
- "NOTICE"
40
- ]
35
+ "files": ["src", "README.md", "LICENSE", "NOTICE"]
41
36
  }
package/src/index.test.ts CHANGED
@@ -1,8 +1,9 @@
1
- import { afterEach, beforeEach, describe, expect, test } from "bun:test";
1
+ import { afterEach, beforeEach, describe, expect, mock, spyOn, test } from "bun:test";
2
+ import * as nodeFs from "node:fs";
2
3
  import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
3
4
  import { tmpdir } from "node:os";
4
5
  import { join } from "node:path";
5
- import { loadRules, renderRules, resolveProfile } from "./index";
6
+ import { RulesEngineError, loadRules, renderRules, resolveProfile } from "./index";
6
7
 
7
8
  let projectRoot: string;
8
9
 
@@ -123,3 +124,45 @@ describe("resolveProfile", () => {
123
124
  expect(resolveProfile("")).toBe("standard");
124
125
  });
125
126
  });
127
+
128
+ describe("RulesEngineError", () => {
129
+ test("carries the 'config' code and the RulesEngineError name", () => {
130
+ const err = new RulesEngineError("nope");
131
+ expect(err).toBeInstanceOf(RulesEngineError);
132
+ expect(err).toBeInstanceOf(Error);
133
+ expect(err.name).toBe("RulesEngineError");
134
+ expect(err.code).toBe("config");
135
+ expect(err.message).toBe("nope");
136
+ });
137
+ });
138
+
139
+ describe("loadRules read-failure path", () => {
140
+ // The bucket/file enumeration runs against the real seeded temp dir; only
141
+ // readFileSync is forced to throw so loadRules' catch -> RulesEngineError
142
+ // branch executes (covering the constructor) without any real read failure.
143
+ afterEach(() => {
144
+ spyOn(nodeFs, "readFileSync").mockRestore();
145
+ });
146
+
147
+ test("wraps a readFileSync failure in a RulesEngineError naming the rule", () => {
148
+ seed("common", "broken.md", "body");
149
+ const spy = spyOn(nodeFs, "readFileSync").mockImplementation(() => {
150
+ throw new Error("EIO simulated read error");
151
+ });
152
+ expect(() => loadRules({ projectRoot })).toThrow(RulesEngineError);
153
+ try {
154
+ loadRules({ projectRoot });
155
+ throw new Error("expected loadRules to throw");
156
+ } catch (err) {
157
+ expect(err).toBeInstanceOf(RulesEngineError);
158
+ expect((err as RulesEngineError).message).toContain("common/broken.md");
159
+ expect((err as RulesEngineError).message).toContain("EIO simulated read error");
160
+ }
161
+ expect(spy).toHaveBeenCalled();
162
+ });
163
+ });
164
+
165
+ // Guard: ensure no mock.module leaked from this file affects sibling suites.
166
+ afterEach(() => {
167
+ mock.restore();
168
+ });