@aiready/contract-enforcement 0.2.6 → 0.2.7

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.
@@ -1,18 +1,19 @@
1
-
2
- > @aiready/contract-enforcement@0.2.6 build /Users/pengcao/projects/aiready/packages/contract-enforcement
3
- > tsup src/index.ts --format cjs,esm --dts
4
-
5
- CLI Building entry: src/index.ts
6
- CLI Using tsconfig: tsconfig.json
7
- CLI tsup v8.5.1
8
- CLI Target: es2020
9
- CJS Build start
10
- ESM Build start
11
- ESM dist/index.mjs 17.28 KB
12
- ESM ⚡️ Build success in 37ms
13
- CJS dist/index.js 18.72 KB
14
- CJS ⚡️ Build success in 39ms
15
- DTS Build start
16
- DTS ⚡️ Build success in 4782ms
17
- DTS dist/index.d.ts 2.45 KB
18
- DTS dist/index.d.mts 2.45 KB
1
+
2
+ 
3
+ > @aiready/contract-enforcement@0.2.7 build /Users/pengcao/projects/aiready/packages/contract-enforcement
4
+ > tsup src/index.ts --format cjs,esm --dts
5
+
6
+ CLI Building entry: src/index.ts
7
+ CLI Using tsconfig: tsconfig.json
8
+ CLI tsup v8.5.1
9
+ CLI Target: es2020
10
+ CJS Build start
11
+ ESM Build start
12
+ CJS dist/index.js 18.88 KB
13
+ CJS ⚡️ Build success in 64ms
14
+ ESM dist/index.mjs 17.44 KB
15
+ ESM ⚡️ Build success in 64ms
16
+ DTS Build start
17
+ DTS ⚡️ Build success in 9740ms
18
+ DTS dist/index.d.ts 2.45 KB
19
+ DTS dist/index.d.mts 2.45 KB
@@ -1,16 +1,18 @@
1
-
2
- > @aiready/contract-enforcement@0.2.5 test /Users/pengcao/projects/aiready/packages/contract-enforcement
3
- > vitest run
4
-
5
-
6
-  RUN  v4.1.1 /Users/pengcao/projects/aiready/packages/contract-enforcement
7
-
8
- ✓ src/__tests__/scoring.test.ts (7 tests) 3ms
9
- ✓ src/__tests__/detector.test.ts (14 tests) 105ms
10
- ✓ src/__tests__/provider.test.ts (5 tests) 3ms
11
-
12
-  Test Files  3 passed (3)
13
-  Tests  26 passed (26)
14
-  Start at  20:27:25
15
-  Duration  4.35s (transform 1.54s, setup 0ms, import 6.86s, tests 111ms, environment 0ms)
16
-
1
+
2
+ 
3
+ > @aiready/contract-enforcement@0.2.6 test /Users/pengcao/projects/aiready/packages/contract-enforcement
4
+ > vitest run
5
+
6
+ [?25l
7
+  RUN  v4.1.1 /Users/pengcao/projects/aiready/packages/contract-enforcement
8
+
9
+ ✓ src/__tests__/scoring.test.ts (7 tests) 5ms
10
+ ✓ src/__tests__/provider.test.ts (5 tests) 4ms
11
+ ✓ src/__tests__/detector.test.ts (15 tests) 47ms
12
+
13
+  Test Files  3 passed (3)
14
+  Tests  27 passed (27)
15
+  Start at  22:04:34
16
+  Duration  1.50s (transform 687ms, setup 0ms, import 2.52s, tests 56ms, environment 0ms)
17
+
18
+ [?25h
package/dist/index.js CHANGED
@@ -143,8 +143,11 @@ function isSwallowedCatch(body, filePath) {
143
143
  const stmt = body[0];
144
144
  if (stmt.type === "ExpressionStatement" && stmt.expression?.type === "CallExpression") {
145
145
  const callee = stmt.expression.callee;
146
- if (callee?.type === "MemberExpression" && callee.object?.type === "Identifier" && callee.object.name === "console")
146
+ if (callee?.type === "MemberExpression" && callee.object?.type === "Identifier" && callee.object.name === "console") {
147
+ const method = callee.property.type === "Identifier" ? callee.property.name : "";
148
+ if (method === "error" || method === "warn") return false;
147
149
  return true;
150
+ }
148
151
  if (isUiComponent) {
149
152
  let calleeName = "";
150
153
  if (callee?.type === "Identifier") calleeName = callee.name;
package/dist/index.mjs CHANGED
@@ -116,8 +116,11 @@ function isSwallowedCatch(body, filePath) {
116
116
  const stmt = body[0];
117
117
  if (stmt.type === "ExpressionStatement" && stmt.expression?.type === "CallExpression") {
118
118
  const callee = stmt.expression.callee;
119
- if (callee?.type === "MemberExpression" && callee.object?.type === "Identifier" && callee.object.name === "console")
119
+ if (callee?.type === "MemberExpression" && callee.object?.type === "Identifier" && callee.object.name === "console") {
120
+ const method = callee.property.type === "Identifier" ? callee.property.name : "";
121
+ if (method === "error" || method === "warn") return false;
120
122
  return true;
123
+ }
121
124
  if (isUiComponent) {
122
125
  let calleeName = "";
123
126
  if (callee?.type === "Identifier") calleeName = callee.name;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiready/contract-enforcement",
3
- "version": "0.2.6",
3
+ "version": "0.2.7",
4
4
  "description": "Measures structural type safety and boundary validation to reduce fallback cascades for AI agents",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -32,7 +32,7 @@
32
32
  "homepage": "https://github.com/caopengau/aiready-contract-enforcement",
33
33
  "dependencies": {
34
34
  "@typescript-eslint/typescript-estree": "^8.53.0",
35
- "@aiready/core": "0.24.6"
35
+ "@aiready/core": "0.24.7"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@types/node": "^24.0.0",
@@ -72,13 +72,25 @@ describe('detectDefensivePatterns', () => {
72
72
  try {
73
73
  doSomething();
74
74
  } catch (e) {
75
- console.error(e);
75
+ console.log(e);
76
76
  }
77
77
  `;
78
78
  const result = detectDefensivePatterns(filePath, code);
79
79
  expect(result.counts['swallowed-error']).toBe(1);
80
80
  });
81
81
 
82
+ it('does not flag console.error as swallowed', () => {
83
+ const code = `
84
+ try {
85
+ doSomething();
86
+ } catch (e) {
87
+ console.error(e);
88
+ }
89
+ `;
90
+ const result = detectDefensivePatterns(filePath, code);
91
+ expect(result.counts['swallowed-error']).toBe(0);
92
+ });
93
+
82
94
  it('does not flag catch blocks with real handling', () => {
83
95
  const code = `
84
96
  try {
package/src/detector.ts CHANGED
@@ -141,13 +141,17 @@ function isSwallowedCatch(
141
141
  stmt.expression?.type === 'CallExpression'
142
142
  ) {
143
143
  const callee = stmt.expression.callee;
144
- // console.log/warn/error is still considered "swallowed" but might be acceptable
144
+ // console.error and console.warn are considered "handling" or at least "reporting"
145
145
  if (
146
146
  callee?.type === 'MemberExpression' &&
147
147
  callee.object?.type === 'Identifier' &&
148
148
  callee.object.name === 'console'
149
- )
150
- return true;
149
+ ) {
150
+ const method =
151
+ callee.property.type === 'Identifier' ? callee.property.name : '';
152
+ if (method === 'error' || method === 'warn') return false;
153
+ return true; // console.log/info/debug etc. are still considered "swallowed"
154
+ }
151
155
 
152
156
  // If it's a UI component and looks like telemetry, it's a false positive
153
157
  if (isUiComponent) {