|
| 1 | +import { readFileSync } from "node:fs"; |
| 2 | +import { join } from "node:path"; |
| 3 | +import { describe, expect, it } from "vitest"; |
| 4 | + |
| 5 | +import { parseMinerGoalSpecContent } from "../../packages/gittensory-engine/src/miner-goal-spec"; |
| 6 | + |
| 7 | +const repoRoot = process.cwd(); |
| 8 | +const schemaPath = join(repoRoot, "packages/gittensory-miner/schema/miner-goal-spec.schema.json"); |
| 9 | +const docPath = join(repoRoot, "packages/gittensory-miner/docs/miner-goal-spec.md"); |
| 10 | +const examplePath = join(repoRoot, ".gittensory-miner.yml.example"); |
| 11 | + |
| 12 | +const SPEC_FIELDS = [ |
| 13 | + "minerEnabled", |
| 14 | + "wantedPaths", |
| 15 | + "blockedPaths", |
| 16 | + "preferredLabels", |
| 17 | + "blockedLabels", |
| 18 | + "maxConcurrentClaims", |
| 19 | + "issueDiscoveryPolicy", |
| 20 | +] as const; |
| 21 | + |
| 22 | +describe("miner goal spec docs (#2300)", () => { |
| 23 | + it("documents every MinerGoalSpec field and the relationship to .gittensory.yml", () => { |
| 24 | + const doc = readFileSync(docPath, "utf8"); |
| 25 | + expect(doc).toContain("Relationship to `.gittensory.yml`"); |
| 26 | + expect(doc).toContain("wantedPaths"); |
| 27 | + expect(doc).toContain("blockedPaths"); |
| 28 | + for (const field of SPEC_FIELDS) { |
| 29 | + expect(doc).toContain(field); |
| 30 | + } |
| 31 | + }); |
| 32 | + |
| 33 | + it("ships a JSON Schema draft 2020-12 with the MinerGoalSpec properties", () => { |
| 34 | + const schema = JSON.parse(readFileSync(schemaPath, "utf8")) as { |
| 35 | + $schema: string; |
| 36 | + properties: Record<string, unknown>; |
| 37 | + }; |
| 38 | + expect(schema.$schema).toBe("https://json-schema.org/draft/2020-12/schema"); |
| 39 | + for (const field of SPEC_FIELDS) { |
| 40 | + expect(schema.properties).toHaveProperty(field); |
| 41 | + } |
| 42 | + }); |
| 43 | + |
| 44 | + it("parses the root example file through the engine parser", () => { |
| 45 | + const example = readFileSync(examplePath, "utf8"); |
| 46 | + const parsed = parseMinerGoalSpecContent(example, ".gittensory-miner.yml.example"); |
| 47 | + expect(parsed.present).toBe(true); |
| 48 | + expect(parsed.spec).toMatchObject({ |
| 49 | + minerEnabled: true, |
| 50 | + wantedPaths: ["src/**"], |
| 51 | + blockedPaths: ["vendor/**", ".github/workflows/**"], |
| 52 | + preferredLabels: ["bug", "enhancement"], |
| 53 | + blockedLabels: ["wontfix", "duplicate"], |
| 54 | + maxConcurrentClaims: 1, |
| 55 | + issueDiscoveryPolicy: "neutral", |
| 56 | + }); |
| 57 | + expect(parsed.warnings).toEqual([]); |
| 58 | + }); |
| 59 | +}); |
0 commit comments