Files
jobtrackingapp/docs/i18n/00/B04_review.py
T

193 lines
12 KiB
Python

"""Explicit disposition of B03's 83 captures; research only, no translation approval."""
from collections import Counter
from functools import lru_cache
import hashlib
import json
from pathlib import Path
import re
import subprocess
HERE = Path(__file__).resolve().parent
ROOT = HERE.parents[2]
SOURCE = '1db5f488f6138e4f0f33749452b7d9f47658f4b0'
B03_HASH = 'b4e91fb2c4821cfadcf58445dbc358f20abb26c505c219681757c0ae22f5b8e3'
C, S, M, T, UI = 'JobTrackerApi/Controllers/', 'JobTrackerApi/Services/', 'JobTrackerApi/Models/', 'JobTrackerApi.Tests/', 'job-tracker-ui/src/'
# Complete containing declarations, followed by supporting type/caller/test contracts.
BLOCKS = {
'preview': (C+'CvVariantController.cs', 322, 348),
'rewrite': (C+'ProfileCvController.cs', 374, 468),
'apply-extraction': (C+'ProfileCvController.Pipeline.cs', 253, 307),
'artifact-cleanup': (C+'ProfileCvController.Pipeline.cs', 391, 401),
'processing': (C+'ProfileCvController.Pipeline.cs', 407, 591),
'prune': (C+'ProfileCvController.Pipeline.cs', 604, 646),
'completion-mail': (C+'ProfileCvController.Pipeline.cs', 648, 665),
'attachment-delete': (C+'AttachmentsController.cs', 171, 252),
'attachment-upload': (C+'AttachmentsController.cs', 255, 391),
'send': (C+'EmailController.cs', 130, 261),
'checkout': (C+'BillingController.cs', 60, 102),
'portal': (C+'BillingController.cs', 106, 130),
'webhook': (C+'BillingController.cs', 135, 224),
'reset-mail': (C+'UsersController.cs', 223, 249),
'test-mail': (C+'UsersController.cs', 255, 284),
'undo': (C+'AdminAuditController.cs', 118, 194),
'letter-render': (S+'CoverLetterDocumentRenderer.cs', 12, 92),
'preview-caller': (C+'CvVariantController.cs', 77, 89),
'preview-client': (UI+'components/CvTemplateThumbnail.tsx', 1, 64),
'render-model-types': (S+'CvRenderModel.cs', 8, 54),
'rewrite-request': (C+'ProfileCvController.cs', 148, 159),
'rewrite-helpers': (C+'ProfileCvController.cs', 575, 623),
'job-types': (M+'JobApplication.cs', 5, 75),
'company-types': (M+'Company.cs', 6, 24),
'account-types': (M+'ApplicationUser.cs', 5, 40),
'run-types': (M+'CvExtraction.cs', 3, 36),
'attempt-types': (M+'EmailSendAttempt.cs', 12, 27),
'metrics-types': (S+'SummarizerService.cs', 16, 50),
'failure-types': (S+'SummarizerService.cs', 71, 84),
'undo-client': (UI+'views/AdminAuditPage.tsx', 67, 86),
'pdf-http-caller': (C+'ApplicationAssetsController.cs', 105, 122),
'pdf-filename': (S+'PlaywrightCvPdfExporter.cs', 50, 61),
'rewrite-test': (T+'ProfileCvControllerTests.cs', 844, 935),
'letter-test': (T+'CoverLetterDocumentPersistenceTests.cs', 88, 116),
'billing-test': (T+'BillingControllerTests.cs', 119, 128),
'email-test': (T+'EmailControllerTests.cs', 45, 69),
}
SCHEMA_POSITIONS = {(20, 0), (20, 2), (21, 0), (21, 2), (24, 0), (24, 2), (25, 0), (25, 2), (26, 0), (26, 2)}
HEADING_POSITIONS = {(record, 1) for record in [20, 21, 24, 25, 26]}
MODEL_IDS = set(range(47, 55))
POLICIES = {
'operator-language': 'Define diagnostic language/exposure in its implementation stage; ILogger templates are not notification/UI copy.',
'preview-language': 'Qualify translated preview headings and cross-occupation example fixtures; never rewrite real career facts.',
'model-language': 'Qualify instruction versus requested output language independently from interface locale; live semantic tests remain blocked.',
'audit-display': 'Define server display versus stable code/client rendering; preserve stored status identities and historical event notes.',
'filename-language': 'Preserve the current filename until its locale/Unicode/header/client contract is qualified.',
}
def sha(data):
return hashlib.sha256(data).hexdigest()
@lru_cache(maxsize=None)
def blob(path):
assert path in {entry[0] for entry in BLOCKS.values()}
return subprocess.check_output(['git', 'show', f'{SOURCE}:{path}'], cwd=ROOT)
def block_for(record):
matches = [name for name, (path, start, end) in BLOCKS.items()
if path == record['source'] and start <= record['line'] <= end]
assert len(matches) == 1, (record['id'], matches)
return matches[0]
def role(record, index, segment):
number = int(record['id'].rsplit('-', 1)[1])
if (number, index) in SCHEMA_POSITIONS or segment == 'cv_processing_failed':
return 'invariant-schema-or-failure-code', None
if (number, index) in HEADING_POSITIONS:
return 'preview-heading-candidate', 'preview-language'
if 20 <= number <= 26:
return 'synthetic-example-value', 'preview-language'
if number in MODEL_IDS:
return 'model-instruction-fragment', 'model-language'
if record['boundary'] == 'diagnostic-template':
return 'operator-log-template', 'operator-language'
if number == 279:
return 'audit-feedback-candidate', 'audit-display'
if number == 346:
return 'output-filename', 'filename-language'
raise AssertionError(('undispositioned capture', record['id'], index))
def parameter_type(name):
types = {
'SectionName': ('string?', 'rewrite', 'private section/display metadata'),
'TemplateId': ('string', 'rewrite-helpers', 'template identifier; preserve identity'),
'TargetRole': ('string?', 'rewrite', 'private career/job role'),
'JobApplicationId': ('int?', 'rewrite-helpers', 'private owned job identifier'),
'HasSourceText': ('bool', 'rewrite', 'presence only, not CV source text'),
'StructuredSectionCount': ('int', 'rewrite', 'collection Count, not source content'),
'AiHealthy': ('bool', 'metrics-types', 'service health signal'),
'AiLastError': ('string?', 'metrics-types', 'upstream diagnostic domain; private values not exported'),
'UserId': ('string identity/storage contract; framework Id declaration external', 'account-types', 'private account identifier'),
'ArtifactPath': ('string', 'artifact-cleanup', 'private filesystem path'),
'RunId': ('int', 'run-types', 'private processing identifier'),
'Category': ('string', 'failure-types', 'stable failure category, not translated prose'),
'ArtifactId': ('int', 'run-types', 'private artifact identifier'),
'Path': ('string', 'run-types', 'private filesystem path'),
'AttachmentId': ('int', 'attachment-delete', 'private attachment identifier'),
'JobId': ('int', 'attachment-upload', 'private owned job identifier'),
'AttemptId': ('Guid', 'attempt-types', 'private delivery-attempt identifier'),
'ExceptionType': ('string framework Type.Name contract', 'send', 'exception type name, not full exception text'),
'SubscriptionId': ('external Stripe Subscription.Id; string? storage sink confirmed, SDK declaration not inspected', 'account-types', 'private provider identifier'),
'Email': ('Identity email value passed to string sender contract; nullable source', 'reset-mail', 'private email address'),
'prev': ('string', 'job-types', 'original stored status identifier; preserve value'),
'job.Status': ('string', 'job-types', 'restored stored status identifier; preserve value'),
}
if name in types:
value, evidence, sensitivity = types[name]
elif name.startswith('jobContext.'):
value, evidence, sensitivity = 'string (coalesced where nullable)', 'job-types', 'private job/source-ad/company/recruiter value; preserve original'
if 'CompanyName' in name or 'Recruiter' in name:
evidence = 'company-types'
elif name in {'sectionName', 'effectiveTargetRole', 'tone', 'language', 'promptBackground'}:
value, evidence, sensitivity = 'string? input, guarded/coalesced before this interpolation', 'rewrite-request', 'private career/editor input; output language independent of UI'
elif name in {'subject', 'style', 'templateGuidance', 'roleGuidance', 'toneGuidance', 'languageGuidance', 'backgroundGuidance'}:
value, evidence, sensitivity = 'string expression', 'rewrite', 'composed instruction frame; may contain private runtime values'
else:
raise AssertionError(('untyped parameter', name))
return {'expression': name, 'sourceTypeContract': value, 'evidenceBlock': evidence, 'sensitivity': sensitivity,
'runtimeValuesExported': False}
def build():
data = (HERE/'B03_CENSUS.json').read_bytes()
assert sha(data) == B03_HASH, 'B03 must remain immutable'
prior = json.loads(data)
contexts, occurrences = [], []
for record in prior['records']:
if not record['unresolvedSegments']:
continue
source = blob(record['source'])
line = source.decode('utf-8').splitlines()[record['line'] - 1]
assert sha(source) == record['sourceSha256'] and sha(line.encode()) == record['sourceLineSha256']
assert line.strip() == record['sourceExpression']
parameters = [] if record['boundary'] == 'synthetic-preview-example' else [parameter_type(name)
for name in sorted(set(re.findall(r'\{([^{}]+)\}', record['sourceExpression'])))]
contexts.append({'recordId': record['id'], 'source': record['source'], 'line': record['line'],
'expression': record['sourceExpression'], 'sourceLineSha256': record['sourceLineSha256'],
'containingDeclaration': block_for(record), 'parameters': parameters,
'note': 'Full statement/declaration is authoritative; lexical fragments are not independent messages.'})
for index, segment in enumerate(record['unresolvedSegments']):
category, policy = role(record, index, segment)
occurrences.append({'id': f'{record["id"]}:U{index + 1:02}', 'recordId': record['id'],
'unresolvedIndex': index, 'originalLexicalCapture': segment, 'sourceRole': category,
'sourceRoleReviewed': True, 'pendingPolicy': policy, 'translationApproved': False,
'runtimeReview': 'not-run', 'nativeReview': 'not-run'})
blocks = []
for name, (path, start, end) in BLOCKS.items():
raw = blob(path)
lines = raw.splitlines(keepends=True)
assert 1 <= start <= end <= len(lines), name
blocks.append({'id': name, 'source': path, 'startLine': start, 'endLine': end,
'sourceSha256': sha(raw), 'rawBlockSha256': sha(b''.join(lines[start - 1:end])),
'firstLine': lines[start - 1].decode().strip(), 'lastLine': lines[end - 1].decode().strip()})
assert len(occurrences) == 83
return {'status': 'research-disposition-only', 'sourceCommit': SOURCE, 'immutableB03Sha256': B03_HASH,
'contexts': contexts, 'occurrences': occurrences, 'evidenceBlocks': blocks,
'policyDecisionsPending': POLICIES, 'counts': {'occurrences': len(occurrences),
'contexts': len(contexts), 'sourceBlobs': len({block['source'] for block in blocks}),
'evidenceBlocks': len(blocks), 'parameters': sum(len(context['parameters']) for context in contexts),
'byRole': dict(Counter(item['sourceRole'] for item in occurrences))},
'productTestsExecuted': False, 'nativeLanguageApproval': False, 'localeOrStageAcceptance': 'NOT GRANTED'}
def validate(payload):
assert payload == build(), 'source, coverage, disposition, type evidence or approval drift'
assert len({row['id'] for row in payload['occurrences']}) == 83
assert all(not row['translationApproved'] for row in payload['occurrences'])
return {'status': 'disposition-integrity-only', 'sourceCommit': SOURCE, 'counts': payload['counts'],
'pendingPolicyDecisions': len(POLICIES), 'unreviewedB03OccurrenceIds': [],
'inputSha256': {name: sha((HERE/name).read_bytes()) for name in ['B03_CENSUS.json', 'B04_DISPOSITIONS.json', 'B04_review.py', 'B04_tests.py']},
'productNativeLanguageTests': 'NOT RUN', 'acceptance': 'NOT GRANTED'}
if __name__ == '__main__':
import sys
if sys.argv[1:] == ['--build']:
(HERE/'B04_DISPOSITIONS.json').write_text(json.dumps(build(), ensure_ascii=False, indent=2)+'\n', encoding='utf-8')
else:
print(json.dumps(validate(json.loads((HERE/'B04_DISPOSITIONS.json').read_text(encoding='utf-8'))), indent=2))