mirror of
https://github.com/deepseek-ai/deepseek-harness
synced 2026-08-15 21:04:50 +00:00
fix(i18n): pin translation snapshots against gc
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
import { spawnSync } from 'node:child_process'
|
||||
import { createHash } from 'node:crypto'
|
||||
|
||||
const SNAPSHOT_REF_PREFIX = 'refs/dsh/translation-pairing/snapshots'
|
||||
|
||||
/** Full SHA-1 Git blob hash (the 40-hex format used by pairing records). */
|
||||
export function gitBlobHash(content: Buffer): string {
|
||||
const hash = createHash('sha1')
|
||||
@@ -11,6 +13,20 @@ export function gitBlobHash(content: Buffer): string {
|
||||
return hash.digest('hex')
|
||||
}
|
||||
|
||||
function runGit(root: string, args: string[], operation: string, input?: Buffer): Buffer {
|
||||
const result = spawnSync('git', ['-C', root, ...args], {
|
||||
input,
|
||||
maxBuffer: 1 << 26,
|
||||
})
|
||||
if (result.error) {
|
||||
throw new Error(`${operation} failed: ${result.error.message}`, { cause: result.error })
|
||||
}
|
||||
if (result.status !== 0) {
|
||||
throw new Error(`${operation} failed with status ${String(result.status)}: ${result.stderr.toString('utf8').trim()}`)
|
||||
}
|
||||
return result.stdout
|
||||
}
|
||||
|
||||
/**
|
||||
* Persist exact working-tree bytes so a pairing record can later recover them
|
||||
* with `git cat-file`, even when they have never appeared in the index or a
|
||||
@@ -19,19 +35,16 @@ export function gitBlobHash(content: Buffer): string {
|
||||
*/
|
||||
export function storeGitBlob(root: string, content: Buffer): string {
|
||||
const expected = gitBlobHash(content)
|
||||
const result = spawnSync('git', ['-C', root, 'hash-object', '-w', '--stdin'], {
|
||||
input: content,
|
||||
maxBuffer: 1 << 26,
|
||||
})
|
||||
if (result.error) {
|
||||
throw new Error(`git hash-object -w --stdin failed: ${result.error.message}`, { cause: result.error })
|
||||
}
|
||||
if (result.status !== 0) {
|
||||
throw new Error(`git hash-object -w --stdin failed with status ${String(result.status)}: ${result.stderr.toString('utf8').trim()}`)
|
||||
}
|
||||
const stored = result.stdout.toString('utf8').trim()
|
||||
const stored = runGit(root, ['hash-object', '-w', '--stdin'], 'git hash-object -w --stdin', content)
|
||||
.toString('utf8')
|
||||
.trim()
|
||||
if (stored !== expected) {
|
||||
throw new Error(`git hash-object -w --stdin returned unexpected object ID ${JSON.stringify(stored)}; expected ${expected}`)
|
||||
}
|
||||
runGit(
|
||||
root,
|
||||
['update-ref', `${SNAPSHOT_REF_PREFIX}/${stored}`, stored],
|
||||
'git update-ref for translation snapshot',
|
||||
)
|
||||
return stored
|
||||
}
|
||||
|
||||
@@ -45,6 +45,10 @@ describe('translation pairing snapshots', () => {
|
||||
const objectId = storeGitBlob(root, content)
|
||||
|
||||
expect(objectId).toBe(gitBlobHash(content))
|
||||
expect(execFileSync('git', [
|
||||
'-C', root, 'rev-parse', `refs/dsh/translation-pairing/snapshots/${objectId}`,
|
||||
], { encoding: 'utf8' }).trim()).toBe(objectId)
|
||||
execFileSync('git', ['-C', root, 'gc', '--prune=now'])
|
||||
expect(execFileSync('git', ['-C', root, 'cat-file', '-p', objectId])).toEqual(content)
|
||||
} finally {
|
||||
rmSync(root, { recursive: true, force: true })
|
||||
|
||||
Reference in New Issue
Block a user