Initial service implementation
ci / test (push) Successful in 11s

This commit is contained in:
Luna
2026-07-16 20:16:05 +00:00
commit 18d0b333d2
27 changed files with 2953 additions and 0 deletions
+77
View File
@@ -0,0 +1,77 @@
import test from "node:test";
import assert from "node:assert/strict";
import request from "supertest";
import { createApp } from "../dist/app.js";
const baseConfig = {
apiKey: "",
cacheSweepIntervalMs: 300000,
cacheTtlMs: 300000,
cloneTimeoutMs: 45000,
defaultSshKeyName: "loc_via_git_ed25519",
generateSshKeyIfMissing: false,
maxConcurrentScans: 4,
port: 3000,
rateLimitMax: 30,
rateLimitWindowMs: 300000,
sshKeysDir: "/tmp/keys",
tempRoot: "/tmp/loc-via-git",
trustProxy: false
};
test("GET /loc returns count metadata", async () => {
const app = createApp(baseConfig, {
getHealth: () => ({ cacheEntries: 1, inFlight: 0, maxConcurrentScans: 4, activeScans: 0, queuedScans: 0 }),
getPublicKey: async () => "ssh-ed25519 AAAA",
getDefaultKeyName: () => "loc_via_git_ed25519",
count: async (requestInput) => ({
repo: requestInput.repo,
ref: requestInput.ref,
sshKey: requestInput.sshKey,
cached: false,
lineCount: 12,
fileCount: 3,
languages: [{ language: "TypeScript", files: 3, lines: 12 }],
scannedAt: "2026-01-01T00:00:00.000Z",
durationMs: 123
})
});
const response = await request(app).get("/loc?repo=https://example.com/repo.git");
assert.equal(response.status, 200);
assert.equal(response.body.lineCount, 12);
assert.equal(response.body.languages[0].language, "TypeScript");
});
test("GET /ssh/public-key returns text without auth", async () => {
const app = createApp({ ...baseConfig, apiKey: "secret" }, {
getHealth: () => ({ cacheEntries: 0, inFlight: 0, maxConcurrentScans: 4, activeScans: 0, queuedScans: 0 }),
getPublicKey: async () => "ssh-ed25519 AAAAB3 key",
getDefaultKeyName: () => "loc_via_git_ed25519",
count: async () => {
throw new Error("not used");
}
});
const response = await request(app).get("/ssh/public-key");
assert.equal(response.status, 200);
assert.equal(response.text, "ssh-ed25519 AAAAB3 key");
});
test("GET /loc enforces api key when configured", async () => {
const app = createApp({ ...baseConfig, apiKey: "secret" }, {
getHealth: () => ({ cacheEntries: 0, inFlight: 0, maxConcurrentScans: 4, activeScans: 0, queuedScans: 0 }),
getPublicKey: async () => "ssh-ed25519 AAAA",
getDefaultKeyName: () => "loc_via_git_ed25519",
count: async () => {
throw new Error("not used");
}
});
const response = await request(app).get("/loc?repo=https://example.com/repo.git");
assert.equal(response.status, 401);
});
+11
View File
@@ -0,0 +1,11 @@
import test from "node:test";
import assert from "node:assert/strict";
import { detectLanguage } from "../dist/language.js";
test("detectLanguage recognizes common source files", () => {
assert.equal(detectLanguage("/tmp/example.tsx"), "TypeScript React");
assert.equal(detectLanguage("/tmp/Dockerfile"), "Dockerfile");
assert.equal(detectLanguage("/tmp/types.d.ts"), "TypeScript");
assert.equal(detectLanguage("/tmp/file.unknown"), "Plain Text");
});
Executable
+13
View File
@@ -0,0 +1,13 @@
#!/usr/bin/env bash
set -euo pipefail
base_url="${1:-http://127.0.0.1:3000}"
repo="${2:-https://github.com/octocat/Hello-World.git}"
health="$(curl -fsS "$base_url/health")"
loc_json="$(curl -fsS "$base_url/loc?repo=$repo")"
loc_text="$(curl -fsS "$base_url/loc.txt?repo=$repo")"
printf 'health: %s\n' "$health"
printf 'loc json: %s\n' "$loc_json"
printf 'loc text: %s\n' "$loc_text"