@handsupmin/gc-tree 0.8.2 → 0.8.3
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,6 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { readFile, readdir } from 'node:fs/promises';
|
|
3
|
+
import { join } from 'node:path';
|
|
2
4
|
import { parseIndexEntries } from './markdown.js';
|
|
3
|
-
import {
|
|
5
|
+
import { resolveContext } from './resolve.js';
|
|
6
|
+
import { branchDocsDir, branchIndexPath, DEFAULT_BRANCH } from './paths.js';
|
|
4
7
|
import { ensureBranchExists, statusForBranch } from './store.js';
|
|
5
8
|
const VALID_CATEGORIES = new Set(['role', 'repos', 'domain', 'workflows', 'conventions', 'infra', 'verification']);
|
|
6
9
|
export async function verifyOnboarding({ home, branch, }) {
|
|
@@ -12,6 +15,42 @@ export async function verifyOnboarding({ home, branch, }) {
|
|
|
12
15
|
const indexedDocCount = docs.length;
|
|
13
16
|
const hasDocs = status.doc_count > 0 && indexedDocCount > 0;
|
|
14
17
|
const qualityIssues = [];
|
|
18
|
+
const docsDir = branchDocsDir(home, gcBranch);
|
|
19
|
+
const sourceDocs = await listSourceDocPaths(docsDir);
|
|
20
|
+
const nonIndexSourceDocs = sourceDocs.filter((path) => !/(^|\/)index\.md$/i.test(path));
|
|
21
|
+
if (sourceDocs.some((path) => /(^|\/)index\.md$/i.test(path))) {
|
|
22
|
+
qualityIssues.push('Source docs must not include docs/index.md. The branch-level index.md is the only dictionary.');
|
|
23
|
+
}
|
|
24
|
+
const indexedPaths = new Set(docs.map((doc) => doc.path));
|
|
25
|
+
for (const path of indexedPaths) {
|
|
26
|
+
if (!existsSync(join(branchDirForDoc(home, gcBranch), path))) {
|
|
27
|
+
qualityIssues.push(`Index points to a missing source doc: ${path}.`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
for (const path of nonIndexSourceDocs) {
|
|
31
|
+
const indexPath = `docs/${path}`;
|
|
32
|
+
if (!indexedPaths.has(indexPath)) {
|
|
33
|
+
qualityIssues.push(`Source doc is not reachable from index.md: ${indexPath}.`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
const pathLikeLabels = docs
|
|
37
|
+
.filter((doc) => /^\.?docs\//i.test(doc.label) || /\.md$/i.test(doc.label))
|
|
38
|
+
.map((doc) => doc.label);
|
|
39
|
+
if (pathLikeLabels.length > 0) {
|
|
40
|
+
qualityIssues.push(`Index labels must be search terms, not paths: ${dedupe(pathLikeLabels).join(', ')}.`);
|
|
41
|
+
}
|
|
42
|
+
const prefixedLabels = docs
|
|
43
|
+
.filter((doc) => /^(repo|repository|domain|workflow|convention|role|infra|verification)\s*:/i.test(doc.label))
|
|
44
|
+
.map((doc) => doc.label);
|
|
45
|
+
if (prefixedLabels.length > 0) {
|
|
46
|
+
qualityIssues.push(`Index labels must not keep category prefixes: ${dedupe(prefixedLabels).join(', ')}.`);
|
|
47
|
+
}
|
|
48
|
+
const invalidCategories = docs
|
|
49
|
+
.filter((doc) => doc.category !== 'general' && !VALID_CATEGORIES.has(doc.category))
|
|
50
|
+
.map((doc) => `${doc.label} (${doc.category})`);
|
|
51
|
+
if (invalidCategories.length > 0) {
|
|
52
|
+
qualityIssues.push(`Index contains invalid categories: ${dedupe(invalidCategories).join(', ')}.`);
|
|
53
|
+
}
|
|
15
54
|
if (hasDocs && indexedDocCount >= 3) {
|
|
16
55
|
const categoryCounts = new Map();
|
|
17
56
|
for (const doc of docs) {
|
|
@@ -25,6 +64,25 @@ export async function verifyOnboarding({ home, branch, }) {
|
|
|
25
64
|
const generalDocLabels = docs.filter((d) => d.category === 'general').map((d) => d.label);
|
|
26
65
|
qualityIssues.push(`${generalCount} doc(s) still have category "general": ${generalDocLabels.join(', ')}. Move them to one of: ${[...VALID_CATEGORIES].join(', ')}.`);
|
|
27
66
|
}
|
|
67
|
+
if (indexedDocCount >= 5) {
|
|
68
|
+
const presentCategories = new Set(docs.map((doc) => doc.category));
|
|
69
|
+
const missingCore = ['role', 'repos', 'domain', 'workflows'].filter((category) => !presentCategories.has(category));
|
|
70
|
+
if (missingCore.length > 0) {
|
|
71
|
+
qualityIssues.push(`Onboarding is missing core dictionary categories: ${missingCore.join(', ')}. Capture them or explicitly add small docs for unavailable categories.`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (status.warnings.length > 0) {
|
|
76
|
+
qualityIssues.push(...status.warnings);
|
|
77
|
+
}
|
|
78
|
+
const searchQuality = [];
|
|
79
|
+
for (const doc of docs.slice(0, 12)) {
|
|
80
|
+
const resolved = await resolveContext({ home, branch: gcBranch, query: doc.label });
|
|
81
|
+
const matched = resolved.matches.some((match) => match.path === doc.path);
|
|
82
|
+
searchQuality.push({ query: doc.label, expected_path: doc.path, matched });
|
|
83
|
+
if (!matched) {
|
|
84
|
+
qualityIssues.push(`Resolve smoke test failed: query "${doc.label}" did not return ${doc.path}.`);
|
|
85
|
+
}
|
|
28
86
|
}
|
|
29
87
|
const complete = hasDocs && qualityIssues.length === 0;
|
|
30
88
|
return {
|
|
@@ -35,6 +93,7 @@ export async function verifyOnboarding({ home, branch, }) {
|
|
|
35
93
|
docs,
|
|
36
94
|
warnings: status.warnings,
|
|
37
95
|
quality_issues: qualityIssues,
|
|
96
|
+
search_quality: searchQuality,
|
|
38
97
|
message: complete
|
|
39
98
|
? `Onboarding is complete for gc-branch "${gcBranch}".`
|
|
40
99
|
: hasDocs
|
|
@@ -42,3 +101,23 @@ export async function verifyOnboarding({ home, branch, }) {
|
|
|
42
101
|
: `Onboarding is incomplete for gc-branch "${gcBranch}". Docs or index entries are missing.`,
|
|
43
102
|
};
|
|
44
103
|
}
|
|
104
|
+
async function listSourceDocPaths(dir, prefix = '') {
|
|
105
|
+
const entries = await readdir(dir, { withFileTypes: true }).catch(() => []);
|
|
106
|
+
const files = [];
|
|
107
|
+
for (const entry of entries) {
|
|
108
|
+
const relative = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
109
|
+
if (entry.isDirectory()) {
|
|
110
|
+
files.push(...(await listSourceDocPaths(join(dir, entry.name), relative)));
|
|
111
|
+
}
|
|
112
|
+
else if (entry.isFile() && entry.name.endsWith('.md')) {
|
|
113
|
+
files.push(relative);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return files.sort();
|
|
117
|
+
}
|
|
118
|
+
function branchDirForDoc(home, branch) {
|
|
119
|
+
return join(home, 'branches', branch);
|
|
120
|
+
}
|
|
121
|
+
function dedupe(values) {
|
|
122
|
+
return [...new Set(values)];
|
|
123
|
+
}
|