22'use strict'
33
44const assert = require ( 'assert' )
5+ const { execFileSync } = require ( 'child_process' )
56const fs = require ( 'fs' )
67const path = require ( 'path' )
78const {
@@ -33,6 +34,13 @@ function profile(fileName) {
3334 return fs . readFileSync ( path . join ( PROFILE_ROOT , fileName ) , 'utf8' )
3435}
3536
37+ function currentSourceGitHead ( ) {
38+ return String ( execFileSync ( 'git' , [ 'rev-parse' , 'HEAD' ] , {
39+ cwd : ROOT ,
40+ encoding : 'utf8'
41+ } ) ) . trim ( )
42+ }
43+
3644function currentRecord ( overrides = { } ) {
3745 return {
3846 schemaVersion : 'ProfileCurrentTruthV1' ,
@@ -82,10 +90,10 @@ probe('ProfileCurrentTruthV1 strict generic schema', () => {
8290} )
8391
8492probe ( 'Profile current truth matches package, workflow, release, and refs' , ( ) => {
85- const releaseProfileText = ACTIVE_PROFILE_AVAILABLE ? profile ( '05-发布规范.md' ) : recordMarkdown ( )
86- const overviewProfileText = ACTIVE_PROFILE_AVAILABLE ? profile ( '01-项目信息.md' ) : `# Overview\n\n${ PROFILE_CURRENT_TRUTH_REF } \n`
87- const testProfileText = ACTIVE_PROFILE_AVAILABLE ? profile ( '04-测试规范.md' ) : `# Test\n\n${ PROFILE_CURRENT_TRUTH_REF } \n`
88- const docsProfileText = ACTIVE_PROFILE_AVAILABLE ? profile ( '07-用户文档与契约规范.md' ) : `# Docs\n\n${ PROFILE_CURRENT_TRUTH_REF } \n`
93+ const releaseProfileText = recordMarkdown ( candidateRecord ( ) )
94+ const overviewProfileText = `# Overview\n\n${ PROFILE_CURRENT_TRUTH_REF } \n`
95+ const testProfileText = `# Test\n\n${ PROFILE_CURRENT_TRUTH_REF } \n`
96+ const docsProfileText = `# Docs\n\n${ PROFILE_CURRENT_TRUTH_REF } \n`
8997 const result = validateDevCodexCurrentTruth ( {
9098 releaseProfileText,
9199 overviewProfileText,
@@ -100,12 +108,25 @@ probe('Profile current truth matches package, workflow, release, and refs', () =
100108 assert . strictEqual ( result . record . publishRun . id , '31910507513' )
101109 assert . strictEqual ( result . record . githubRelease . tag , 'v1.17.8' )
102110
111+ if ( ACTIVE_PROFILE_AVAILABLE ) {
112+ const activeResult = validateDevCodexCurrentTruth ( {
113+ releaseProfileText : profile ( '05-发布规范.md' ) ,
114+ overviewProfileText : profile ( '01-项目信息.md' ) ,
115+ testProfileText : profile ( '04-测试规范.md' ) ,
116+ docsProfileText : profile ( '07-用户文档与契约规范.md' ) ,
117+ packageVersion : JSON . parse ( read ( 'package.json' ) ) . version ,
118+ gitHead : currentSourceGitHead ( ) ,
119+ workflowText : read ( '.github/workflows/ci.yml' )
120+ } )
121+ assert . deepStrictEqual ( activeResult . errors , [ ] )
122+ }
123+
103124 const missingOverviewRef = validateDevCodexCurrentTruth ( {
104125 releaseProfileText,
105126 overviewProfileText : '# Overview without current truth ref\n' ,
106127 testProfileText,
107128 docsProfileText,
108- packageVersion : '1.17.8 ' ,
129+ packageVersion : '1.17.9 ' ,
109130 gitHead : '85f3a8eadf61b0614f88d6817d255f255de968c2' ,
110131 workflowText : read ( '.github/workflows/ci.yml' )
111132 } )
@@ -117,7 +138,7 @@ probe('Profile current truth matches package, workflow, release, and refs', () =
117138 overviewProfileText,
118139 testProfileText,
119140 docsProfileText,
120- packageVersion : '1.17.8 ' ,
141+ packageVersion : '1.17.9 ' ,
121142 gitHead : '85f3a8eadf61b0614f88d6817d255f255de968c2' ,
122143 workflowText : changedWorkflow
123144 } )
0 commit comments