knowledgeWorkflow.test.mjs 2.22 KB
import assert from 'node:assert/strict'
import fs from 'node:fs'
import path from 'node:path'
import test from 'node:test'
import { fileURLToPath } from 'node:url'

const projectRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../..')

function read(relativePath) {
  return fs.readFileSync(path.join(projectRoot, relativePath), 'utf8')
}

test('project quality workflow keeps advisory drift, affected PRs and master full tests', () => {
  const workflow = read('.github/workflows/project-quality.yml')

  assert.match(workflow, /pull_request:/)
  assert.match(workflow, /branches:\s*\n\s*- master/)
  assert.match(workflow, /knowledge-drift:[\s\S]*continue-on-error: true/)
  assert.match(workflow, /test:affected[\s\S]*--base[\s\S]*--head/)
  assert.match(workflow, /master-tests:[\s\S]*npm test/)
})

test('live workflow is manual, profile-bound, secret-only and write-gated', () => {
  const workflow = read('.github/workflows/live-order-tests.yml')

  assert.match(workflow, /workflow_dispatch:/)
  assert.match(workflow, /mingming-dev/)
  assert.match(workflow, /bobo-test/)
  assert.match(workflow, /inputs\.allow_writes != true/)
  assert.match(workflow, /LIVE_ALLOW_WRITES: '1'/)
  assert.match(workflow, /secrets\.LIVE_MINGMING_MOBILE/)
  assert.match(workflow, /secrets\.LIVE_BOBO_MOBILE/)
  assert.doesNotMatch(workflow, /\b1\d{10}\b/)
})

test('documentation entry describes setup, querying, maintenance and Live boundaries', () => {
  const documentation = read('docs/README.md')

  for (const required of [
    'npm run knowledge:build',
    'npm run knowledge:check',
    'npm run impact',
    'npm run test:affected',
    'npm test',
    '### 日常维护',
    '### Live 自动化',
  ]) {
    assert.ok(documentation.includes(required), `missing docs entry: ${required}`)
  }
})

test('root README exposes the knowledge workflow to first-time contributors', () => {
  const readme = read('README.md')

  for (const required of [
    '领域知识图谱与增量测试',
    'npm run knowledge:build',
    'npm run knowledge:check',
    'npm run impact',
    'npm run test:affected',
    './docs/README.md#领域知识图谱搭建与使用',
  ]) {
    assert.ok(readme.includes(required), `missing root README entry: ${required}`)
  }
})