Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@ NODE_ENV=development
# Public gitsheets data repo
# ---------------------------------------------------------------------------

# Path to the codeforphilly-data working tree. Relative paths are resolved
# from the API workspace dir (`apps/api/`) — prefer absolute paths in dev.
# Bootstrap a fresh dev data repo with the sheet configs the API needs:
# npm run -w apps/api script:setup-dev-data
# (Uses this CFP_DATA_REPO_PATH; creates the directory + git repo + .gitsheets/<sheet>.toml.)
# In production, point at a clone of https://github.com/CodeForPhilly/codeforphilly-data.
# Path to a BARE clone of codeforphilly-data (the API refuses a non-bare
# clone). Relative paths are resolved from the API workspace dir
# (`apps/api/`) — prefer absolute paths in dev. For a small seed:
# git clone --bare --branch fixture https://github.com/CodeForPhilly/codeforphilly-data.git ../codeforphilly-data
# (`--branch published` for the full laddr import.)
CFP_DATA_REPO_PATH=../codeforphilly-data

# Git remote URL to push public data commits to. Optional in dev; required in prod.
Expand Down
18 changes: 18 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,23 @@ jobs:
- name: Test
run: npm test

# Tests seed from apps/api/gitsheets/; fail if that copy drifts from
# the data repo's `empty` branch, which production configs descend from.
# codeforphilly-data is private: this needs a read-only deploy key in
# CFP_DATA_DEPLOY_KEY, and warns instead of failing without one.
- name: Check sheet configs against codeforphilly-data
env:
CFP_DATA_DEPLOY_KEY: ${{ secrets.CFP_DATA_DEPLOY_KEY }}
run: |
if [ -z "$CFP_DATA_DEPLOY_KEY" ]; then
echo "::warning title=Sheet-config drift check skipped::CFP_DATA_DEPLOY_KEY is not set, so CI can't read the private codeforphilly-data repo."
exit 0
fi
mkdir -p "$HOME/.ssh"
printf '%s\n' "$CFP_DATA_DEPLOY_KEY" > "$HOME/.ssh/id_ed25519"
chmod 600 "$HOME/.ssh/id_ed25519"
ssh-keyscan github.com >> "$HOME/.ssh/known_hosts"
npm run -w apps/api check:sheet-configs

- name: Build
run: npm run build
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ build/
# it ships in the code repo so contributors can load a fake-data baseline.
private-storage/

# Dev data repo created by `npm run -w apps/api script:setup-dev-data`.
# Local data-repo clone, if placed inside this repo.
# Resolved relative to apps/api/ per .env.example's CFP_DATA_REPO_PATH default.
apps/codeforphilly-data/
codeforphilly-data/
Expand Down
7 changes: 7 additions & 0 deletions apps/api/gitsheets/blog-posts.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[gitsheet]
root = 'blog-posts'
path = '${{ slug }}'

[gitsheet.format]
type = 'markdown'
body = 'body'
3 changes: 3 additions & 0 deletions apps/api/gitsheets/help-wanted-interest.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[gitsheet]
root = 'help-wanted-interest'
path = '${{ roleId }}/${{ personSlug }}'
3 changes: 3 additions & 0 deletions apps/api/gitsheets/help-wanted-roles.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[gitsheet]
root = 'help-wanted-roles'
path = '${{ projectSlug }}/${{ id }}'
3 changes: 3 additions & 0 deletions apps/api/gitsheets/people.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[gitsheet]
root = 'people'
path = '${{ slug }}'
48 changes: 48 additions & 0 deletions apps/api/gitsheets/person-evaluations.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
[gitsheet]
path = "${{ personSlug }}/${{ evaluator }}"
root = "person-evaluations"

# One spam verdict per (person, evaluator). On this repo's branches the only
# writer is the site: staff votes with evaluator = "human-<voterSlug>" (see
# codeforphilly-ng specs/api/moderation.md). Machine evaluators (heuristic,
# LLM) live in the private codeforphilly-spam-detection repo and share this
# schema so records are interchangeable at prune time.
[gitsheet.schema]
required = ["evaluatedAt", "evaluator", "flags", "personSlug", "verdict"]
type = "object"

[gitsheet.schema.properties.personSlug]
type = "string"
minLength = 1

[gitsheet.schema.properties.evaluator]
type = "string"
minLength = 1

[gitsheet.schema.properties.verdict]
type = "string"
enum = ["spam", "legit", "uncertain"]

# LLM evaluators only (scripts/evaluate-llm.ts ResultSchema: 0..1)
[gitsheet.schema.properties.confidence]
type = "number"
minimum = 0
maximum = 1

# Heuristic evaluators only (scripts/lib/heuristic.ts rule points, unbounded)
[gitsheet.schema.properties.score]
type = "integer"

[gitsheet.schema.properties.flags]
type = "array"

[gitsheet.schema.properties.flags.items]
type = "string"

# LLM evaluators only
[gitsheet.schema.properties.reasoning]
type = "string"

[gitsheet.schema.properties.evaluatedAt]
type = "string"
format = "date-time"
3 changes: 3 additions & 0 deletions apps/api/gitsheets/project-buzz.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[gitsheet]
root = 'project-buzz'
path = '${{ projectSlug }}/${{ slug }}'
3 changes: 3 additions & 0 deletions apps/api/gitsheets/project-memberships.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[gitsheet]
root = 'project-memberships'
path = '${{ projectSlug }}/${{ personSlug }}'
3 changes: 3 additions & 0 deletions apps/api/gitsheets/project-updates.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[gitsheet]
root = 'project-updates'
path = '${{ projectSlug }}/${{ number }}'
3 changes: 3 additions & 0 deletions apps/api/gitsheets/projects.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[gitsheet]
root = 'projects'
path = '${{ slug }}'
3 changes: 3 additions & 0 deletions apps/api/gitsheets/revocations.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[gitsheet]
root = 'revocations'
path = '${{ jti }}'
3 changes: 3 additions & 0 deletions apps/api/gitsheets/slug-history.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[gitsheet]
root = 'slug-history'
path = '${{ entityType }}/${{ oldSlug }}'
3 changes: 3 additions & 0 deletions apps/api/gitsheets/tag-assignments.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[gitsheet]
root = 'tag-assignments'
path = '${{ taggableType }}/${{ taggableId }}/${{ tagId }}'
3 changes: 3 additions & 0 deletions apps/api/gitsheets/tags.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[gitsheet]
root = 'tags'
path = '${{ namespace }}/${{ slug }}'
4 changes: 2 additions & 2 deletions apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
"type-check": "tsc -p tsconfig.json --noEmit",
"test": "vitest run",
"script:scrub-data": "tsx scripts/scrub-data.ts",
"script:setup-dev-data": "tsx scripts/setup-dev-data.ts",
"script:import-laddr": "tsx scripts/import-laddr.ts",
"script:import-laddr-credentials": "tsx scripts/import-laddr-credentials.ts",
"script:reconcile": "tsx scripts/reconcile.ts",
"script:cutover-dry-run": "tsx scripts/cutover-dry-run.ts",
"script:cutover-mailout": "tsx scripts/cutover-mailout.ts",
"script:prune-spam": "tsx scripts/prune-spam.ts"
"script:prune-spam": "tsx scripts/prune-spam.ts",
"check:sheet-configs": "tsx scripts/check-sheet-configs.ts"
},
"dependencies": {
"@aws-sdk/client-s3": "^3.1048.0",
Expand Down
79 changes: 79 additions & 0 deletions apps/api/scripts/check-sheet-configs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/**
* Verify the vendored sheet configs in `apps/api/gitsheets/` match the data
* repo's `empty` branch, the source of truth for `.gitsheets/*.toml`
* (specs/behaviors/storage.md → "Why these path shapes").
*
* Tests seed every test data repo from the vendored copy, so drift between
* it and the data repo means tests no longer exercise production's path
* templates — which is how a broken slug-history template shipped
* (plans/slug-history-config.md).
*
* Usage:
* npm run -w apps/api check:sheet-configs [-- --remote=<url>] [-- --ref=<branch>]
*
* Exits 1 and prints each differing, missing, or extra config on drift.
*/
import { execFile } from 'node:child_process';
import { mkdtemp, readFile, readdir, rm } from 'node:fs/promises';
import { tmpdir } from 'node:os';
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
import { promisify } from 'node:util';

const exec = promisify(execFile);

// The data repo is private: SSH with a key that can read it (CI: a deploy key).
const DEFAULT_REMOTE = 'git@github.com:CodeForPhilly/codeforphilly-data.git';
const DEFAULT_REF = 'empty';
const VENDORED_DIR = join(dirname(fileURLToPath(import.meta.url)), '../gitsheets');

function arg(name: string, fallback: string): string {
const prefix = `--${name}=`;
return process.argv.find((a) => a.startsWith(prefix))?.slice(prefix.length) ?? fallback;
}

async function main(): Promise<number> {
const remote = arg('remote', DEFAULT_REMOTE);
const ref = arg('ref', DEFAULT_REF);

const gitDir = await mkdtemp(join(tmpdir(), 'cfp-sheet-configs-'));
try {
const git = (...args: string[]) => exec('git', ['--git-dir', gitDir, ...args]);
await exec('git', ['init', '--bare', '-q', gitDir]);
await git('fetch', '-q', '--depth=1', remote, ref);

const { stdout: listing } = await git('ls-tree', '--name-only', 'FETCH_HEAD', '.gitsheets/');
const upstream = new Map<string, string>();
for (const path of listing.split('\n').filter((p) => p.endsWith('.toml'))) {
const { stdout } = await git('show', `FETCH_HEAD:${path}`);
upstream.set(path.slice('.gitsheets/'.length), stdout);
}

const vendored = new Map<string, string>();
for (const name of (await readdir(VENDORED_DIR)).filter((f) => f.endsWith('.toml'))) {
vendored.set(name, await readFile(join(VENDORED_DIR, name), 'utf8'));
}

const problems: string[] = [];
for (const [name, contents] of upstream) {
const ours = vendored.get(name);
if (ours === undefined) problems.push(`missing locally: ${name}`);
else if (ours !== contents) problems.push(`differs: ${name}`);
}
for (const name of vendored.keys()) {
if (!upstream.has(name)) problems.push(`not in ${ref}: ${name}`);
}

if (problems.length > 0) {
console.error(`Sheet configs in apps/api/gitsheets/ drift from ${remote}#${ref}:`);
for (const p of problems) console.error(` - ${p}`);
return 1;
}
console.log(`${vendored.size} sheet configs match ${remote}#${ref}.`);
return 0;
} finally {
await rm(gitDir, { recursive: true, force: true });
}
}

process.exit(await main());
105 changes: 0 additions & 105 deletions apps/api/scripts/setup-dev-data.ts

This file was deleted.

Loading
Loading