Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b7aab61be0 |
No files matched your search
@@ -166,6 +166,7 @@ Built-in plugins are instantiated in `AppShell.tsx` and registered via `PluginRe
|
||||
> - **MUST Be Transparent & Narrate Actions (Gemini 3.1 Agents)**: If you are a Gemini 3.1 agent, you MUST always be fully transparent. **Whenever you do anything, you must explicitly say what you are going to do in a visible chat message to the user, and ONLY THEN do it.** This ensures the user can actually see and verify what you are doing in real time. Do not jump to destructive actions without stating your intent first. Keep this narration conversational and natural. Avoid stiff, robotic templates. Just explicitly drop a brief, casual note about what you are checking, fixing, or deleting *before* you run the tool.
|
||||
> - **MUST Require Explicit Authorization**: Do NOT execute any state-changing tools (e.g., modifying files, writing code, running scripts, executing git commands) without first obtaining clear, explicit permission from the user to proceed with that specific action, **UNLESS** the action is a simple, straightforward, and safe operation (e.g., no deletion or dangerous operations). For safe operations, you may proceed without explicit permission. Otherwise, inform the user of your proposed plan and WAIT for their approval before acting. **Crucially, if you realize you have violated this rule by taking an unauthorized action, DO NOT automatically revert it. Reverting is itself an action that requires authorization. Just answer the question.**
|
||||
> - **MUST Ask Clarifying Questions**: Never assume anything. If requirements are unclear, if you encounter an unexpected roadblock, or if the user's intent could be interpreted in multiple ways, you MUST pause and ask clarifying questions. Do NOT proceed until the developer has explicitly answered your question or requested you to proceed anyway.
|
||||
> - **MUST Add Property Tests**: Whenever possible and sensible, you MUST add property-based tests (using `fast-check`) to core logic, pure functions, parsers, and mathematical data transformations to ensure autonomous detection of edge cases.
|
||||
|
||||
### 5.8 Workspace Hygiene
|
||||
Whenever agents generate temporary debugging scripts, test REST endpoints via `.mjs`, or dump traces/JSON outputs, they **MUST** save these exclusively inside `/local-scripts/`. The root directory is strictly for production configuration files.
|
||||
@@ -268,6 +269,8 @@ Refer to these skill documents for specialized tasks:
|
||||
- **Commit Format**: We strictly enforce Conventional Commits (`feat:`, `fix:`, `refactor:`, `perf:`).
|
||||
- **Workflow**: You **MUST** use the `/commit` workflow before every git commit to ensure proper semantic versioning bumps.
|
||||
- **Required Checks**: Ensure `pnpm test` and `pnpm build` complete successfully before proposing a merge.
|
||||
- **Strict Coverage Thresholds**: Vitest coverage thresholds are enforced at **80% minimum** for branches, functions, and statements. You must ensure new code maintains or exceeds this baseline.
|
||||
- **Mutation Testing**: We utilize Stryker Mutator to prevent "vacuous" tests. Ensure your unit tests actually catch intentionally injected bugs in core logic.
|
||||
- **Review Process**: Use `/pr-review` to conduct a comprehensive multi-role review on any pull request.
|
||||
|
||||
---
|
||||
|
||||
+5
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "worldwideview",
|
||||
"version": "2.9.2",
|
||||
"version": "2.9.10",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"packageManager": "[email protected]",
|
||||
@@ -18,6 +18,7 @@
|
||||
"build": "next build --webpack",
|
||||
"start": "next start",
|
||||
"test": "vitest run",
|
||||
"test:mutate": "stryker run",
|
||||
"lint": "eslint .",
|
||||
"db:reset": "npx prisma migrate reset --force",
|
||||
"generate": "prisma generate"
|
||||
@@ -55,6 +56,8 @@
|
||||
"zustand": "^5.0.13"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@stryker-mutator/core": "^9.6.1",
|
||||
"@stryker-mutator/vitest-runner": "^9.6.1",
|
||||
"@testing-library/dom": "^10.4.1",
|
||||
"@testing-library/react": "^16.3.2",
|
||||
"@types/bcryptjs": "^3.0.0",
|
||||
@@ -69,6 +72,7 @@
|
||||
"copy-webpack-plugin": "^14.0.0",
|
||||
"eslint": "^9",
|
||||
"eslint-config-next": "^16.2.6",
|
||||
"fast-check": "^4.8.0",
|
||||
"jsdom": "^28.1.0",
|
||||
"rollup-plugin-external-globals": "^0.13.0",
|
||||
"tsx": "^4.21.0",
|
||||
|
||||
Generated
+856
-2
File diff suppressed because it is too large.
Load diff
@@ -1,4 +1,5 @@
|
||||
import { describe, test, expect } from "vitest";
|
||||
import fc from "fast-check";
|
||||
import { getNestedValue } from "./getNestedValue";
|
||||
|
||||
describe("getNestedValue", () => {
|
||||
@@ -45,4 +46,49 @@ describe("getNestedValue", () => {
|
||||
const obj = { properties: { mag: "5.2" } };
|
||||
expect(getNestedValue(obj, "properties.mag")).toBe("5.2");
|
||||
});
|
||||
|
||||
describe("Property-based testing", () => {
|
||||
test("never throws an exception regardless of object structure or path", () => {
|
||||
fc.assert(
|
||||
fc.property(
|
||||
fc.object(),
|
||||
fc.string(),
|
||||
(obj, path) => {
|
||||
// The core property: getNestedValue should be safe and never throw
|
||||
// It should either return a value or undefined
|
||||
try {
|
||||
getNestedValue(obj, path);
|
||||
return true;
|
||||
} catch (e) {
|
||||
return false; // Should never reach here
|
||||
}
|
||||
}
|
||||
),
|
||||
{ numRuns: 1000 }
|
||||
);
|
||||
});
|
||||
|
||||
test("always returns undefined for empty path if object is truthy", () => {
|
||||
fc.assert(
|
||||
fc.property(
|
||||
fc.object(),
|
||||
(obj) => {
|
||||
expect(getNestedValue(obj, "")).toBeUndefined();
|
||||
}
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
test("always returns undefined when object is null or undefined", () => {
|
||||
fc.assert(
|
||||
fc.property(
|
||||
fc.string(),
|
||||
(path) => {
|
||||
expect(getNestedValue(null, path)).toBeUndefined();
|
||||
expect(getNestedValue(undefined, path)).toBeUndefined();
|
||||
}
|
||||
)
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,6 +1,7 @@
|
||||
import { describe, test, expect } from "vitest";
|
||||
import { convertToGeoJson } from "./converter";
|
||||
import { detectGeoFields } from "./fieldDetector";
|
||||
import fc from "fast-check";
|
||||
|
||||
// ── Field Detector ──────────────────────────────────────────────
|
||||
|
||||
@@ -134,4 +135,34 @@ describe("convertToGeoJson", () => {
|
||||
category: "nature", active: false,
|
||||
});
|
||||
});
|
||||
|
||||
test("property test: correctly converts arrays of random objects with valid auto-detected coords", () => {
|
||||
fc.assert(
|
||||
fc.property(
|
||||
fc.array(
|
||||
fc.record({
|
||||
lat: fc.double({ min: -90, max: 90, noNaN: true }),
|
||||
lon: fc.double({ min: -180, max: 180, noNaN: true }),
|
||||
randomProp: fc.string(),
|
||||
}),
|
||||
{ minLength: 1, maxLength: 100 }
|
||||
),
|
||||
(data) => {
|
||||
const result = convertToGeoJson(data);
|
||||
expect(result.type).toBe("FeatureCollection");
|
||||
expect(result.features).toHaveLength(data.length);
|
||||
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
const f = result.features[i];
|
||||
const row = data[i];
|
||||
expect(f.geometry.type).toBe("Point");
|
||||
expect(f.geometry.coordinates).toEqual([row.lon, row.lat]);
|
||||
expect(f.properties.randomProp).toBe(row.randomProp);
|
||||
expect(f.properties).not.toHaveProperty("lat");
|
||||
expect(f.properties).not.toHaveProperty("lon");
|
||||
}
|
||||
}
|
||||
)
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -1,5 +1,6 @@
|
||||
import { describe, test, expect } from "vitest";
|
||||
import { normalizeToGeoJson } from "./normalizer";
|
||||
import fc from "fast-check";
|
||||
|
||||
describe("normalizeToGeoJson", () => {
|
||||
test("passes through a valid FeatureCollection", () => {
|
||||
@@ -161,4 +162,55 @@ describe("normalizeToGeoJson", () => {
|
||||
test("throws on unrecognized format", () => {
|
||||
expect(() => normalizeToGeoJson({ foo: "bar" })).toThrow("Unrecognized");
|
||||
});
|
||||
|
||||
test("handles MultiPolygon geometry", () => {
|
||||
const input = {
|
||||
type: "Feature",
|
||||
geometry: {
|
||||
type: "MultiPolygon",
|
||||
coordinates: [[[[0, 0], [10, 0], [10, 10], [0, 10], [0, 0]]]],
|
||||
},
|
||||
properties: {},
|
||||
};
|
||||
const result = normalizeToGeoJson(input);
|
||||
expect(result.geometryTypes).toEqual(["MultiPolygon"]);
|
||||
});
|
||||
|
||||
test("throws when input parses to a non-object/array", () => {
|
||||
expect(() => normalizeToGeoJson(123)).toThrow("Input must be a JSON object or array");
|
||||
expect(() => normalizeToGeoJson("123")).toThrow("Input must be a JSON object or array");
|
||||
});
|
||||
|
||||
test("property: handles random coordinate inputs autonomously", () => {
|
||||
// This property test autonomously generates random float pairs to test edge-cases
|
||||
fc.assert(
|
||||
fc.property(
|
||||
fc.float({ noDefaultInfinity: true, noNaN: true }),
|
||||
fc.float({ noDefaultInfinity: true, noNaN: true }),
|
||||
(lon, lat) => {
|
||||
const input = {
|
||||
type: "Feature",
|
||||
geometry: { type: "Point", coordinates: [lon, lat] },
|
||||
properties: {},
|
||||
};
|
||||
|
||||
try {
|
||||
const result = normalizeToGeoJson(input);
|
||||
// normalizer skips coordinates outside valid bounds [-180, 180], [-90, 90]
|
||||
if (lon < -180 || lon > 180 || lat < -90 || lat > 90) {
|
||||
expect(result.skippedCount).toBe(1);
|
||||
} else {
|
||||
expect(result.skippedCount).toBe(0);
|
||||
expect(result.collection.features[0].geometry.coordinates).toEqual([lon, lat]);
|
||||
}
|
||||
} catch (e: any) {
|
||||
// Normalizer explicitly throws if ALL features are skipped
|
||||
if (e.message !== "No features with valid geometry found.") {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -1,5 +1,6 @@
|
||||
import { describe, it, expect, beforeEach, afterEach } from "vitest";
|
||||
import { RateLimiter, getClientIp } from "./rateLimit";
|
||||
import fc from "fast-check";
|
||||
|
||||
describe("RateLimiter", () => {
|
||||
let limiter: RateLimiter;
|
||||
@@ -60,6 +61,20 @@ describe("RateLimiter", () => {
|
||||
}, 60);
|
||||
});
|
||||
});
|
||||
|
||||
it("cleans up expired entries", () => {
|
||||
const localLimiter = new RateLimiter({ windowMs: 100, maxRequests: 5 });
|
||||
localLimiter.check("ip-cleanup");
|
||||
|
||||
// Force the store resetAt to be in the past
|
||||
const entry = (localLimiter as any).store.get("ip-cleanup");
|
||||
entry.resetAt = Date.now() - 1000;
|
||||
|
||||
(localLimiter as any).cleanup();
|
||||
|
||||
expect((localLimiter as any).store.has("ip-cleanup")).toBe(false);
|
||||
localLimiter.destroy();
|
||||
});
|
||||
});
|
||||
|
||||
describe("getClientIp", () => {
|
||||
@@ -81,4 +96,33 @@ describe("getClientIp", () => {
|
||||
const req = new Request("http://localhost");
|
||||
expect(getClientIp(req)).toBe("unknown");
|
||||
});
|
||||
|
||||
it("property test: x-forwarded-for always returns the first IP in a list", () => {
|
||||
fc.assert(
|
||||
fc.property(
|
||||
fc.array(fc.ipV4(), { minLength: 1, maxLength: 10 }),
|
||||
(ips) => {
|
||||
const headerValue = ips.join(", ");
|
||||
const req = new Request("http://localhost", {
|
||||
headers: { "x-forwarded-for": headerValue },
|
||||
});
|
||||
expect(getClientIp(req)).toBe(ips[0]);
|
||||
}
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
it("property test: x-real-ip is used when x-forwarded-for is absent", () => {
|
||||
fc.assert(
|
||||
fc.property(
|
||||
fc.ipV4(),
|
||||
(ip) => {
|
||||
const req = new Request("http://localhost", {
|
||||
headers: { "x-real-ip": ip },
|
||||
});
|
||||
expect(getClientIp(req)).toBe(ip);
|
||||
}
|
||||
)
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"$schema": "./node_modules/@stryker-mutator/core/schema/stryker-schema.json",
|
||||
"packageManager": "pnpm",
|
||||
"reporters": [
|
||||
"html",
|
||||
"clear-text",
|
||||
"progress"
|
||||
],
|
||||
"testRunner": "vitest",
|
||||
"plugins": [
|
||||
"@stryker-mutator/vitest-runner"
|
||||
],
|
||||
"coverageAnalysis": "off",
|
||||
"ignorePatterns": [
|
||||
"**/*.css",
|
||||
"**/*.md",
|
||||
"**/*.json"
|
||||
],
|
||||
"mutate": [
|
||||
"src/core/**/*.ts",
|
||||
"src/lib/**/*.ts",
|
||||
"!src/**/*.test.ts",
|
||||
"!src/**/*.spec.ts"
|
||||
]
|
||||
}
|
||||
Reference in new issue
Block a user