refactor(sdk): migrate background-knowledge-demands and meaning-directness onto the contract factory - #237
Merged
Merged
Conversation
…tness onto the contract factory
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Pull request overview
Refactors the TypeScript SDK’s background-knowledge-demands and meaning-directness evaluators to use the shared single-step contract factory, aligning preprocessing (FK), telemetry stage naming, and supported grade derivation with what the contracts declare.
Changes:
- Migrated both evaluators to
defineSingleStepEvaluator, removing bespoke prompt/flow code and relying on contract-derived preprocessing and metadata. - Tightened the
meaning-directnessunit test to assert the exact{fk_score}substitution result and ensure the placeholder is replaced. - Updated the registry conformance gap list to remove these evaluators from
PREPROCESSING_GAPS(leaving only vocabulary-complexity).
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| sdks/typescript/src/evaluators/student-facing-text/ela-reading/meaning-directness.ts | Refactored evaluator to single-step factory with contract-based prompts/preprocessing. |
| sdks/typescript/src/evaluators/student-facing-text/ela-reading/background-knowledge-demands.ts | Refactored evaluator to single-step factory with contract-based prompts/preprocessing. |
| sdks/typescript/src/prompts/meaning-directness/index.ts | Removed bespoke prompt wrapper module (now using factory-rendered templates). |
| sdks/typescript/src/prompts/background-knowledge-demands/index.ts | Removed bespoke prompt wrapper module (now using factory-rendered templates). |
| sdks/typescript/tests/unit/evaluators/meaning-directness.test.ts | Strengthened assertion for FK score substitution to avoid a vacuous regex match. |
| sdks/typescript/tests/unit/registry-conformance.test.ts | Updated PREPROCESSING_GAPS list/comments to reflect the migration. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Both contracts are structurally identical to
organizational-structureandpurpose-clarity, which already run on the factory:text+grade_levelin, one Google step, oneflesch_kincaid_gradepreprocessing entry. The two bespoke files restated all of that in code. 451 lines deleted, 72 added; each evaluator goes from 235 lines to 66.Closes 2 of the 3
PREPROCESSING_GAPSentries.vocabulary-complexitystays, because it is multi-step and cannot move until stepconditionsemantics are settled.Three observable changes
Everything else — model, temperature, grades, prompts, error wrapping, telemetry shape — the factory already derives from the same contract, so it is unchanged.
fk_scorenow uses the declared implementation. These two called the hand-rolledcalculateFleschKincaidGrade; the contract declarestext-readability.fleschKincaidGraderounded to 2dp, which is what the factory runs and what their four siblings already used. For the test text inmeaning-directness.test.tsthat is 6.8 rather than 6.14.Neither implementation matches Python
textstat, and the declared one is the further out of the two. That is not made worse here — it is consolidated: all five single-step FK evaluators now share one code path, so the fix in feat(sdk): add a textstat-exact Flesch-Kincaid and a benchmark report #236 becomes a single change inpreprocessing.tsinstead of five migrations. feat(sdk): add a textstat-exact Flesch-Kincaid and a benchmark report #236 is parked on legal review.Telemetry stage names now match the contract.
smk_evaluation→evaluate_background_knowledge_demands, andconventionality_evaluation→evaluate_meaning_directness. Both old names came from earlier evaluator names and appeared in no contract. (sentence-structurestill has this defect and is not touched here.)supportedGradesis derived rather than restated. Both files hardcoded['3'…'12']; the schemas declare exactly that, so the values do not change.A vacuous test, fixed
meaning-directness.test.tsasserted the prompt contained an FK score withtoMatch(/\d+(\.\d+)?/). The grade level in the same prompt satisfies that, so it passed with preprocessing switched off entirely. It now pins the exact value the declared implementation produces, and that the placeholder was substituted at all.Confirmed load-bearing: forcing the old hand-rolled value through
runPreprocessingStepfails it.Validation
typecheck,lint,test:unit(1080),build,scripts/check.pyfk_score, so the change did not move the declared score expectationsmain(1080 both sides)src/prompts/background-knowledge-demands/andsrc/prompts/meaning-directness/, whose only importers were the two rewritten filessingle-step.ts(72.6%) andpreprocessing.ts(93.1%) — the code now carrying these two evaluators. Every surviving mutant is a log message, an error-message separator, or a fallback literal on a path no contract reaches; no behavioural mutant survived. Asserting log wording would be brittle and protect nothing.