fix: publish LCOV in Sonar CI so PR quality gate passes
sonar / sonar (push) Skipped
sonar / sonar (pull_request) Failing after 1m35s
sonar / sonar (push) Skipped
sonar / sonar (pull_request) Failing after 1m35s
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -22,6 +22,17 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Setup Node.js
|
||||||
|
uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: "22"
|
||||||
|
cache: npm
|
||||||
|
|
||||||
|
- name: Install, test, coverage
|
||||||
|
run: |
|
||||||
|
npm ci
|
||||||
|
npm run test:coverage
|
||||||
|
|
||||||
- name: SonarQube Scan + Quality Gate
|
- name: SonarQube Scan + Quality Gate
|
||||||
uses: sonarsource/sonarqube-scan-action@v5
|
uses: sonarsource/sonarqube-scan-action@v5
|
||||||
env:
|
env:
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ data/
|
|||||||
*.sqlite-journal
|
*.sqlite-journal
|
||||||
*.sqlite-wal
|
*.sqlite-wal
|
||||||
*.sqlite-shm
|
*.sqlite-shm
|
||||||
|
coverage/
|
||||||
.scannerwork/
|
.scannerwork/
|
||||||
graphify-out/
|
graphify-out/
|
||||||
_plane*
|
_plane*
|
||||||
|
|||||||
+2
-1
@@ -11,7 +11,8 @@
|
|||||||
"start": "node dist/hello.js",
|
"start": "node dist/hello.js",
|
||||||
"typecheck": "tsc --noEmit",
|
"typecheck": "tsc --noEmit",
|
||||||
"migrate": "npm run build && node dist/db/migrate.js",
|
"migrate": "npm run build && node dist/db/migrate.js",
|
||||||
"test": "npm run build && node --test dist/**/*.test.js"
|
"test": "npm run build && node --test dist/**/*.test.js",
|
||||||
|
"test:coverage": "npm run build && node -e \"require('fs').mkdirSync('coverage',{recursive:true})\" && node --experimental-test-coverage --test-reporter=spec --test-reporter-destination=stdout --test-reporter=lcov --test-reporter-destination=coverage/lcov.info --test dist/**/*.test.js"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@opentelemetry/api": "^1.9.1",
|
"@opentelemetry/api": "^1.9.1",
|
||||||
|
|||||||
@@ -5,4 +5,6 @@ sonar.sources=src
|
|||||||
sonar.tests=src
|
sonar.tests=src
|
||||||
sonar.test.inclusions=**/*.test.ts
|
sonar.test.inclusions=**/*.test.ts
|
||||||
sonar.exclusions=**/*.test.ts
|
sonar.exclusions=**/*.test.ts
|
||||||
|
sonar.javascript.lcov.reportPaths=coverage/lcov.info
|
||||||
|
sonar.coverage.exclusions=**/*.test.ts
|
||||||
sonar.sourceEncoding=UTF-8
|
sonar.sourceEncoding=UTF-8
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
import assert from "node:assert/strict";
|
||||||
|
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
||||||
|
import { tmpdir } from "node:os";
|
||||||
|
import { join } from "node:path";
|
||||||
|
import test from "node:test";
|
||||||
|
import { loadDotEnv } from "./env.js";
|
||||||
|
|
||||||
|
test("loadDotEnv loads missing keys from .env without overriding", () => {
|
||||||
|
const dir = mkdtempSync(join(tmpdir(), "ticketlab-env-"));
|
||||||
|
const key = `TICKETLAB_ENV_TEST_${Date.now()}`;
|
||||||
|
try {
|
||||||
|
writeFileSync(join(dir, ".env"), `${key}=from-file\n# comment\nOTHER=1\n`, "utf8");
|
||||||
|
delete process.env[key];
|
||||||
|
loadDotEnv(dir);
|
||||||
|
assert.equal(process.env[key], "from-file");
|
||||||
|
|
||||||
|
process.env[key] = "already-set";
|
||||||
|
writeFileSync(join(dir, ".env"), `${key}=should-not-win\n`, "utf8");
|
||||||
|
loadDotEnv(dir);
|
||||||
|
assert.equal(process.env[key], "already-set");
|
||||||
|
} finally {
|
||||||
|
delete process.env[key];
|
||||||
|
rmSync(dir, { recursive: true, force: true });
|
||||||
|
}
|
||||||
|
});
|
||||||
+17
-1
@@ -1,6 +1,6 @@
|
|||||||
import assert from "node:assert/strict";
|
import assert from "node:assert/strict";
|
||||||
import { describe, it } from "node:test";
|
import { describe, it } from "node:test";
|
||||||
import { greet } from "./hello.js";
|
import { greet, main } from "./hello.js";
|
||||||
|
|
||||||
describe("greet", () => {
|
describe("greet", () => {
|
||||||
it("returns the default greeting", () => {
|
it("returns the default greeting", () => {
|
||||||
@@ -11,3 +11,19 @@ describe("greet", () => {
|
|||||||
assert.equal(greet("World"), "Hello, World!");
|
assert.equal(greet("World"), "Hello, World!");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("main emits telemetry and logs greeting", async () => {
|
||||||
|
process.env.OTEL_EXPORTER_OTLP_ENDPOINT =
|
||||||
|
process.env.OTEL_EXPORTER_OTLP_ENDPOINT ?? "http://127.0.0.1:4318";
|
||||||
|
const logs: unknown[] = [];
|
||||||
|
const original = console.log;
|
||||||
|
console.log = (...args: unknown[]) => {
|
||||||
|
logs.push(args);
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
await main();
|
||||||
|
assert.deepEqual(logs, [["Hello, TicketLab MCP!"]]);
|
||||||
|
} finally {
|
||||||
|
console.log = original;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
import assert from "node:assert/strict";
|
||||||
|
import test from "node:test";
|
||||||
|
import { SeverityNumber, startTelemetry } from "./telemetry.js";
|
||||||
|
|
||||||
|
test("startTelemetry emits and shuts down without throwing", async () => {
|
||||||
|
process.env.OTEL_EXPORTER_OTLP_ENDPOINT =
|
||||||
|
process.env.OTEL_EXPORTER_OTLP_ENDPOINT ?? "http://127.0.0.1:4318";
|
||||||
|
process.env.OTEL_SERVICE_NAME = "ticketlab-test";
|
||||||
|
|
||||||
|
const telemetry = startTelemetry("ticketlab-test");
|
||||||
|
const counter = telemetry.meter.createCounter("ticketlab_test_runs_total");
|
||||||
|
|
||||||
|
await telemetry.tracer.startActiveSpan("ticketlab.test", async (span) => {
|
||||||
|
counter.add(1, { component: "test" });
|
||||||
|
telemetry.logger.emit({
|
||||||
|
severityNumber: SeverityNumber.INFO,
|
||||||
|
severityText: "INFO",
|
||||||
|
body: "telemetry self-check",
|
||||||
|
attributes: { "ticketlab.event": "test" },
|
||||||
|
});
|
||||||
|
span.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
await telemetry.shutdown();
|
||||||
|
assert.equal(typeof SeverityNumber.INFO, "number");
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user