a6ee31f55a
* feat(wisdom): add trusted publish and install foundation
* feat(wisdom): add private contribution loop
* feat(wisdom): add managed consumption workflows
* fix(wisdom): close cross-repository safety gaps
* fix(wisdom): align local package and lifecycle policy
* fix(wisdom): require explicit profile setup
* docs(wisdom): repin reconciled gateway head
* fix(wisdom): fence content downloads and approval receipts
* docs(wisdom): record generation-fenced downloads
* docs(wisdom): record unified delivery PR
* fix(ci): stop passing invalid classifier inputs
* docs(wisdom): remove internal requirements ledger
* feat(wisdom): localize dashboard and desktop copy
* feat(wisdom): complete local contribution and consumption UX
* style(wisdom): satisfy desktop lint
* chore(wisdom): refresh requirements pin
* test(dashboard): allow formatted profile copy
* test(wisdom): stabilize desktop interaction coverage
* fix(wisdom): surface dashboard action failures
* fix(wisdom): add repeatable Portal demo login
* feat(wisdom): add actionable skill notifications
* feat(wisdom): add notification install and update actions
* fix(wisdom): make Telegram skill alerts actionable
* fix(wisdom): always refresh demo Agent login
* feat(wisdom): embed Telegram notification actions
* fix(wisdom): preserve Telegram notifications after actions
* fix(wisdom): keep Telegram notification cards readable
* feat(wisdom): add Telegram candidate approval flow
* feat(wisdom): explain Telegram qualification reasons
* fix(wisdom): reconcile cross-surface candidate actions
* feat(telegram): add Collective Wisdom management command
* chore(wisdom): refresh Gateway contract pin
* chore(wisdom): advance Gateway contract pin
* feat(wisdom): align command UX across clients
* feat(slack): add Collective Wisdom management parity
* feat(wisdom): add security and professionalism reviews
* feat(wisdom): add first-time qualification guidance
* feat(wisdom): simplify qualification sharing choices
* feat(skills): add optional editorial metadata
* feat(wisdom): enrich legacy skill presentation
* fix(wisdom): harden review and update boundaries
* fix(wisdom): emit canonical review timestamps
* fix(wisdom): align with merged gateway and main
* wisdom: add agent-led sharing core (policy, evidence, schemas, templates, delivery, weekly job, share/install flows)
- hermes_wisdom/agent_led/: policy resolution (server > local > defaults),
7-day evidence builder that excludes bundled/hub/managed skills and
dismissed/handled/recently-suggested content hashes, strict pydantic
schemas for agent output with repair-or-reject, fixed copy templates
(Share / Teammate / Published / Update / Mute), idempotent retried
delivery ledger with stale-action resolution, weekly review job,
resumable Share and Install flows.
- prompts/: candidate review, recipient recommendation, share packaging.
- tests/wisdom/test_agent_led.py: 30 tests.
* wisdom: agent-led renderers and button action dispatcher
- render.py: Telegram HTML, Slack blocks, Desktop payload; editorial name
is the emphasized line, product label stays separate.
- actions.py: resolve opaque wa:<action>:<dedup> targets via the delivery
ledger; Not now -> dismissal, Mute -> fixed options, Share -> resumable
packaging flow, Install/Update -> plan command. Never publishes/installs.
* wisdom: CLI verbs, agent_led config default, conversational catalog skill
- hermes wisdom browse/review-week/act/share/dismiss/mute (all --json).
- wisdom.agent_led config block, default enabled.
- SKILL.md rewritten so natural-language catalog questions map to the CLI
verbs, share/install flows and fixed notification templates.
* wisdom: wire agent-led weekly review into gateway tick and Telegram buttons
- gateway housekeeping tick calls maybe_run_weekly_review with a home
channel sender when a Telegram adapter is available.
- Telegram: wa: callbacks resolved through the ledger (stale-safe), mute
duration keyboard, send_wisdom_agent_recommendation rich card + fallback.
* fix(wisdom): integrate local mediation and harden model and setup boundaries
* fix(wisdom): honor authoritative recommendation policy and defer on failure
* fix(wisdom): synchronize opaque suppression and recheck delivery preferences
* feat(wisdom): route weekly selection through the session-owned assessment queue
* fix(wisdom): prepare and submit the reviewed generated share package
* feat(wisdom): separate native Share preparation from publication consent
* feat(wisdom): sync native mute choices through a leased preference outbox
* feat(wisdom): bind native mute controls to durable preference choices
* feat(wisdom): add scoped desktop and dashboard notification settings
* fix(wisdom): revalidate feed recommendations before assessment and delivery
* fix(wisdom): persist validated delivery receipts before completing notices
* feat(wisdom): add private notification claim and receipt client
* Persist Wisdom send reservations and recover delivery acknowledgements
* Route legacy Wisdom controls through current native review
* Add typed private Wisdom operation outcome client
* fix(wisdom): make agent-led advice usable in the local demo
* fix(wisdom): keep requested consent outside proactive limits
* fix(wisdom): distinguish unavailable assessments and preserve digest text
* fix(wisdom): assess ongoing usefulness beyond the current task
* fix(wisdom): restore immediate qualification sharing controls
* fix(wisdom): separate qualification review from installation advice
* fix(wisdom): collapse review checklists and simplify sharing copy
* fix(wisdom): show compact sharing progress and publication receipts
* fix(wisdom): require credential prefixes rather than matching skill names
* fix(wisdom): finish package checks before presenting sharing consent
* fix(wisdom): scan local skills before qualification cards
* fix(wisdom): update moderation results on existing sharing cards
* fix(wisdom): keep sharing review accessible from receipt cards
* fix(wisdom): align mediated review cards and collapsible checks
* fix(wisdom): clarify clean security summary wording
* fix(wisdom): normalize consent plans and add explicit recheck
* fix(wisdom): keep install and update receipts concise
* fix(wisdom): collapse assessments and deduplicate operation cards
* fix(wisdom): restore private Portal review from native cards
* fix(wisdom): sync Portal publication to original consent card
* fix(wisdom): show local skill version on sharing cards
* fix(wisdom): skip agent recommendations for self-published versions
* fix(wisdom): simplify candidate notices and local-edit recovery copy
* feat(wisdom): submit locally reviewed packages with one confirmation
* feat(wisdom): expose safe receipt and outcome sync recovery
* wisdom: onboarding notice says detect and share, names the user's own skill
Copy review from the product owner on the first and returning
qualification notices (fixed delivery mode):
- the feature blurb now says the org enabled detection *and sharing*
- both notices say the detected skill is one the user created
- both close with an exclamation mark
Applied identically to hermes_wisdom.notice, the desktop and web i18n
strings, and the tests that assert the sentences.
* wisdom: one opener, no approval line, ask to share after the skill is shown
Product owner review of the candidate card.
- The Hermes written card now opens with the same sentence as the fixed card
("Your organisation has enabled Collective Wisdom, a feature designed to
automatically detect and share useful skills across all team members.")
instead of its own blurb, so there is one first time message.
- "Nothing is shared without your approval." removed from Telegram, Slack
and Desktop. The buttons already make the permission explicit.
- "Would you like to share?" no longer appears before the skill is named.
It is now the last line, after the skill name, description, why suggested
and the checks, and reads "Would you like to share it?" (matching the
agent led template wording).
Tests updated for the new order; proposalNotice removed from all desktop locales.
* wisdom: American spelling, organization
Product owner decision: user facing copy uses American spelling.
Changes "Your organisation" to "Your organization" in the chat notice,
the Hermes written card opener, the desktop and web strings, and the
tests that assert them. Identifiers such as nas_organisation:* and the
German and French locales are untouched.
* wisdom: candidate card copy round 4 (owner review)
Apply the product owner's round 4 copy decisions to the Hermes Collective
Wisdom candidate card on Telegram, Slack, Desktop and the shared views:
1. Hermes-written cards are titled "Hermes Collective Wisdom" instead of
the bare "Collective Wisdom".
2. The "Reusable skill ready to review" line is gone from the candidate
card (Telegram rich card and plain fallback, legacy agent-led share
template).
3. The skill name and description are labelled: "Skill name: <name>" and
"What it does: <description>" (Telegram, Slack, Desktop).
4. "Why suggested:" is now "Why others might benefit:".
5. A passing professionalism review reads "Safe to share at work ✓ (no
inappropriate content found)" with no per-check bullets and no "Pass";
a failed review reads "Needs a look before sharing at work (possible
inappropriate content)" and lists only the checks that flagged
something. Pending/unavailable wording is unchanged.
6. Telegram button toasts: "Will ask later...", "Preparing more
details...", "Sharing...".
7. Qualification reasons: "You used this skill consistently across many
days." and "You've really refined this skill."
8. prompts/wisdom_candidate_review.md asks for a compelling
editorial_name, a simple one_line_description and a compelling
why_coworkers_benefit under 300 characters; "Be concise and
convincing." becomes "Be concise and compelling: the goal is that the
user wants to share it."
Tests updated for the new strings; review_text() gains direct coverage.
* wisdom: re-apply owner copy after rebase
- Native share cards (advice_view/interaction_view): drop the approval line, ask "Would you like to share it?" as the last line after the checks
- Hermes-written completion card titled "Hermes Collective Wisdom"
- Qualification reasons use the owner wording (consistently across many days / really refined)
- American spelling (organization) in remaining English copy
- Desktop test asserts the current Share button; web test matches the returning notice
* fix(wisdom): pin reconciled Gateway and verify Unicode hash vectors
Pin Gateway 60cd2d6b613ae3cd4a6e65155d1142006d907e78 and byte-identical producer artifacts. Verify every content-order case and package-manifest binding. Validation: 186 focused Python tests, Ruff and contract verifier.
* fix(wisdom): reconcile optional SDK tests and frontend lint
* fix(wisdom): default to agent-written notification summaries
* fix(wisdom): restore deferred install review and browse controls
* feat(wisdom): inspect installed setup with exact package provenance
* feat(wisdom): run native-approved installed setup steps with durable evidence
* fix(wisdom): recover interrupted setup with explicit native consent
* feat(wisdom): hand native installs into guided setup review
* fix(wisdom): continue requested setup with fixed notification copy
* fix(wisdom): preserve setup while waiting for a session model
* fix(wisdom): expose canonical setup review controls on desktop
* fix(wisdom): resume setup after recorded automatic updates
* fix(wisdom): make missing setup prerequisites recheckable
* chore(wisdom): align Agent with verified Gateway contract
* fix(wisdom): stop guessing team slugs in portal links
* fix(wisdom): retire pending advice on account sign-out
* fix(wisdom): cancel advice after terminal account revocation
* fix(wisdom): fence feed responses across account sign-out
* fix(wisdom): checkpoint signed-out feed before reactivation
* fix(wisdom): link proactive advice to scoped notification settings
* fix(wisdom): coalesce queued publication recommendations by version
* fix(wisdom): keep package review navigation local and deferable
* fix(wisdom): reflect installed state in discovery controls
* fix(wisdom): show exact checks before command confirmation
* chore(wisdom): pin bounded analytics privacy contract
* chore(wisdom): pin retired legacy notification contract
* feat(wisdom): review publisher usage with exact sharing copy
* fix(wisdom): align discovery and review check summaries
* fix(wisdom): show expired consent before confirmation
* fix(wisdom): require fresh review for legacy install controls
* fix(wisdom): preserve review expiry across check toggles
* fix(wisdom): retain update policy in native install reviews
* fix(wisdom): surface failed native card edits
* fix(wisdom): persist local command approval reviews
* fix(wisdom): use saved approvals for messaging commands
* test(wisdom): provide scan result in setup handoff fixture
* test(wisdom): exercise Telegram approvals with saved review state
* fix(wisdom): retain suppression policy for offline deferral
* fix(wisdom): reconsider candidates after deferred suppression expires
* fix(wisdom): bind review checks and report verified readiness separately
* fix(wisdom): persist accepted publication intent and recover exact outcomes
* fix(sync): pin UTF-8 tree ordering across writers
* chore(wisdom): pin organisation-scoped Gateway authorization
* fix(wisdom): restrict consent delivery to user-facing sessions
* chore(wisdom): refresh reviewed Gateway contract pin
* fix(wisdom): preserve kept tools in Blank Slate exclusions
* test(auth): reset anonymous fixture with a profile-scoped cache
* fix(wisdom): gate local surfaces and work on current profile entitlement
* fix(wisdom): invalidate quiet tool cache on entitlement changes
* test(wisdom): authorize local consent gateway fixtures
* fix(wisdom): keep entitlement decoding free of native crypto imports
* test(wisdom): provide local entitlement to demo CLI subprocess
* ci: leave upstream workflow unchanged in Wisdom PR
* fix(wisdom): ship package and contracts in Nix wheels
---------
Co-authored-by: hbizi <36184542+hbizi@users.noreply.github.com>
488 lines
16 KiB
Python
488 lines
16 KiB
Python
import json
|
|
import sys
|
|
import types
|
|
from datetime import datetime, timedelta, timezone
|
|
from pathlib import Path
|
|
from zoneinfo import ZoneInfo
|
|
|
|
import pytest
|
|
|
|
from hermes_wisdom.qualification import (
|
|
HIGH_USAGE_CONSECUTIVE_BUSINESS_DAYS,
|
|
RETENTION_DAYS,
|
|
_emit_candidate,
|
|
_classify_ambiguous,
|
|
process_due_stability_jobs,
|
|
record_mutation,
|
|
record_successful_use,
|
|
snapshot_tree,
|
|
)
|
|
from hermes_wisdom.store import WisdomStore
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def _authorize_qualification_work(monkeypatch):
|
|
from hermes_cli.config import save_config
|
|
from tests.wisdom.local_auth import authorize_local
|
|
|
|
authorize_local(monkeypatch, "org-1")
|
|
save_config({"wisdom": {"enabled": True, "disclosure_acknowledged_at": "fixture"}})
|
|
|
|
|
|
def _configured_store(tmp_path: Path) -> WisdomStore:
|
|
store = WisdomStore(tmp_path / "state")
|
|
store.installation_identity()
|
|
store.verify_installation_identity("org-1")
|
|
return store
|
|
|
|
|
|
def _skill(tmp_path: Path) -> Path:
|
|
path = tmp_path / "skills" / "learned-skill"
|
|
path.mkdir(parents=True)
|
|
(path / "SKILL.md").write_text(
|
|
"---\n"
|
|
"name: learned-skill\n"
|
|
"description: Use when retaining a learned workflow.\n"
|
|
"metadata:\n"
|
|
" hermes:\n"
|
|
" editorial_name: Learned Workflow\n"
|
|
" editorial_description: Reuse a workflow refined through practice.\n"
|
|
"---\n# One\n",
|
|
encoding="utf-8",
|
|
)
|
|
return path
|
|
|
|
|
|
def _eligible(monkeypatch, skill: Path) -> None:
|
|
monkeypatch.setattr(
|
|
"hermes_wisdom.qualification.get_skills_dir", lambda: skill.parent
|
|
)
|
|
monkeypatch.setattr(
|
|
"hermes_wisdom.qualification._find_skill_dir", lambda _name: skill
|
|
)
|
|
monkeypatch.setattr("hermes_wisdom.qualification.is_bundled", lambda _name: False)
|
|
monkeypatch.setattr(
|
|
"hermes_wisdom.qualification.is_hub_installed", lambda _name: False
|
|
)
|
|
|
|
|
|
def test_high_usage_threshold_uses_consecutive_business_days_and_deduplicates(
|
|
monkeypatch, tmp_path: Path
|
|
):
|
|
skill = _skill(tmp_path)
|
|
_eligible(monkeypatch, skill)
|
|
store = _configured_store(tmp_path)
|
|
monkeypatch.setattr(
|
|
"hermes_wisdom.qualification.get_timezone",
|
|
lambda: ZoneInfo("Australia/Brisbane"),
|
|
)
|
|
start = datetime(2026, 8, 3, 9, tzinfo=ZoneInfo("Australia/Brisbane"))
|
|
business_offsets = (0, 1, 2, 3, 4, 7, 8)
|
|
|
|
for offset in business_offsets[:-1]:
|
|
assert (
|
|
record_successful_use(
|
|
"learned-skill", at=start + timedelta(days=offset), store=store
|
|
)
|
|
is None
|
|
)
|
|
event_id = record_successful_use(
|
|
"learned-skill",
|
|
at=start + timedelta(days=business_offsets[-1]),
|
|
session_id="session-1",
|
|
task_id="task-1",
|
|
store=store,
|
|
)
|
|
assert event_id
|
|
assert (
|
|
record_successful_use(
|
|
"learned-skill",
|
|
at=start + timedelta(days=business_offsets[-1] + 1),
|
|
store=store,
|
|
)
|
|
is None
|
|
)
|
|
events = store.local_events(kind="wisdom.candidate")
|
|
assert len(events) == 1
|
|
assert events[0]["session_id"] == "session-1"
|
|
assert events[0]["payload"]["networked"] is False
|
|
assert events[0]["payload"]["consent_required"] is True
|
|
assert events[0]["payload"]["editorial_name"] == "Learned Workflow"
|
|
assert (
|
|
events[0]["payload"]["editorial_description"]
|
|
== "Reuse a workflow refined through practice."
|
|
)
|
|
assert events[0]["payload"]["local_reasons"] == {
|
|
"consecutive_business_days": HIGH_USAGE_CONSECUTIVE_BUSINESS_DAYS,
|
|
"business_day_timezone": "Australia/Brisbane",
|
|
"business_week": "monday_friday",
|
|
}
|
|
with store.transaction() as db:
|
|
reviews = db.execute(
|
|
"SELECT skill_id,content_hash,state FROM professionalism_review"
|
|
).fetchall()
|
|
assert [tuple(row) for row in reviews] == [
|
|
(events[0]["skill_id"], events[0]["content_hash"], "pending")
|
|
]
|
|
|
|
|
|
def test_candidate_editorial_enrichment_does_not_change_source_hash(
|
|
monkeypatch, tmp_path: Path
|
|
):
|
|
skill = _skill(tmp_path)
|
|
_eligible(monkeypatch, skill)
|
|
store = _configured_store(tmp_path)
|
|
old_hash, old_tree = snapshot_tree(skill)
|
|
skill_id = store.register_skill(
|
|
skill,
|
|
content_hash=old_hash,
|
|
source_kind="local",
|
|
tree=old_tree,
|
|
snapshot_text="workflow",
|
|
)
|
|
|
|
def enrich(path: Path):
|
|
assert path == skill
|
|
return {
|
|
"editorial_name": "Human Friendly Workflow",
|
|
"editorial_description": "Reuse a workflow refined through practice.",
|
|
"changed": False,
|
|
}
|
|
|
|
monkeypatch.setattr(
|
|
"hermes_wisdom.qualification.ensure_skill_editorial_metadata", enrich
|
|
)
|
|
event_id = _emit_candidate(
|
|
store,
|
|
skill_id=skill_id,
|
|
skill_name="learned-skill",
|
|
content_hash=old_hash,
|
|
qualification="high_usage",
|
|
local_reasons={},
|
|
session_id=None,
|
|
task_id=None,
|
|
)
|
|
|
|
assert event_id
|
|
new_hash, _tree = snapshot_tree(skill)
|
|
event = store.local_events(kind="wisdom.candidate")[0]
|
|
assert new_hash == old_hash
|
|
assert event["content_hash"] == old_hash
|
|
assert event["payload"]["editorial_name"] == "Human Friendly Workflow"
|
|
assert store.local_skill(skill_id)["current_hash"] == old_hash
|
|
|
|
|
|
def test_weekend_usage_neither_advances_nor_breaks_business_day_streak(
|
|
monkeypatch, tmp_path: Path
|
|
):
|
|
skill = _skill(tmp_path)
|
|
_eligible(monkeypatch, skill)
|
|
store = _configured_store(tmp_path)
|
|
monkeypatch.setattr(
|
|
"hermes_wisdom.qualification.get_timezone",
|
|
lambda: ZoneInfo("Australia/Brisbane"),
|
|
)
|
|
start = datetime(2026, 8, 3, 9, tzinfo=ZoneInfo("Australia/Brisbane"))
|
|
|
|
for offset in (0, 1, 2, 3, 4, 5, 6, 7):
|
|
assert (
|
|
record_successful_use(
|
|
"learned-skill", at=start + timedelta(days=offset), store=store
|
|
)
|
|
is None
|
|
)
|
|
assert record_successful_use(
|
|
"learned-skill", at=start + timedelta(days=8), store=store
|
|
)
|
|
|
|
|
|
def test_midweek_gap_resets_then_rebuilds_business_day_streak(
|
|
monkeypatch, tmp_path: Path
|
|
):
|
|
skill = _skill(tmp_path)
|
|
_eligible(monkeypatch, skill)
|
|
store = _configured_store(tmp_path)
|
|
monkeypatch.setattr(
|
|
"hermes_wisdom.qualification.get_timezone",
|
|
lambda: ZoneInfo("Australia/Brisbane"),
|
|
)
|
|
start = datetime(2026, 8, 3, 9, tzinfo=ZoneInfo("Australia/Brisbane"))
|
|
|
|
for offset in (0, 1, 3, 4, 7, 8, 9, 10):
|
|
assert (
|
|
record_successful_use(
|
|
"learned-skill", at=start + timedelta(days=offset), store=store
|
|
)
|
|
is None
|
|
)
|
|
assert record_successful_use(
|
|
"learned-skill", at=start + timedelta(days=11), store=store
|
|
)
|
|
|
|
|
|
def test_profile_timezone_controls_the_qualification_day(monkeypatch, tmp_path: Path):
|
|
skill = _skill(tmp_path)
|
|
_eligible(monkeypatch, skill)
|
|
store = _configured_store(tmp_path)
|
|
monkeypatch.setattr(
|
|
"hermes_wisdom.qualification.get_timezone",
|
|
lambda: ZoneInfo("Australia/Brisbane"),
|
|
)
|
|
|
|
# Sunday in UTC is already Monday in the configured profile timezone.
|
|
record_successful_use(
|
|
"learned-skill",
|
|
at=datetime(2026, 8, 2, 16, tzinfo=timezone.utc),
|
|
store=store,
|
|
)
|
|
with store.transaction() as db:
|
|
row = db.execute("SELECT day_local,timezone_name FROM usage_day").fetchone()
|
|
assert tuple(row) == ("2026-08-03", "Australia/Brisbane")
|
|
|
|
|
|
def test_usage_retention_is_bounded(monkeypatch, tmp_path: Path):
|
|
skill = _skill(tmp_path)
|
|
_eligible(monkeypatch, skill)
|
|
store = _configured_store(tmp_path)
|
|
monkeypatch.setattr(
|
|
"hermes_wisdom.qualification.get_timezone", lambda: ZoneInfo("UTC")
|
|
)
|
|
start = datetime(2026, 1, 1, tzinfo=timezone.utc)
|
|
for offset in range(RETENTION_DAYS + 8):
|
|
record_successful_use(
|
|
"learned-skill", at=start + timedelta(days=offset * 2), store=store
|
|
)
|
|
with store.transaction() as db:
|
|
rows = db.execute(
|
|
"SELECT day_local FROM usage_day ORDER BY day_local"
|
|
).fetchall()
|
|
assert len(rows) <= (RETENTION_DAYS + 1) // 2
|
|
assert rows[0][0] >= (start.date() + timedelta(days=50)).isoformat()
|
|
|
|
|
|
def test_structural_refinements_schedule_restart_safe_stability(
|
|
monkeypatch, tmp_path: Path
|
|
):
|
|
skill = _skill(tmp_path)
|
|
_eligible(monkeypatch, skill)
|
|
store = _configured_store(tmp_path)
|
|
start = datetime(2026, 8, 1, tzinfo=timezone.utc)
|
|
record_successful_use("learned-skill", at=start, store=store)
|
|
|
|
for index in range(3):
|
|
refs = skill / "refs"
|
|
refs.mkdir(exist_ok=True)
|
|
(refs / f"decision-{index}.md").write_text(
|
|
f"decision {index}", encoding="utf-8"
|
|
)
|
|
record_mutation(
|
|
"learned-skill", at=start + timedelta(days=index + 1), store=store
|
|
)
|
|
|
|
restarted = WisdomStore(store.root)
|
|
event_id = record_successful_use(
|
|
"learned-skill",
|
|
at=start + timedelta(days=10),
|
|
session_id="session-stable",
|
|
store=restarted,
|
|
)
|
|
assert event_id
|
|
event = restarted.local_events(kind="wisdom.candidate")[0]
|
|
assert event["qualification"] == "refinement"
|
|
assert event["payload"]["local_reasons"]["meaningful_refinements"] == 3
|
|
|
|
|
|
def test_due_stability_runs_without_another_use_and_keeps_session(
|
|
monkeypatch, tmp_path: Path
|
|
):
|
|
skill = _skill(tmp_path)
|
|
_eligible(monkeypatch, skill)
|
|
store = _configured_store(tmp_path)
|
|
start = datetime(2026, 8, 1, tzinfo=timezone.utc)
|
|
record_successful_use("learned-skill", at=start, store=store)
|
|
for index in range(3):
|
|
refs = skill / "refs"
|
|
refs.mkdir(exist_ok=True)
|
|
(refs / f"step-{index}.md").write_text(str(index), encoding="utf-8")
|
|
record_mutation(
|
|
"learned-skill",
|
|
at=start + timedelta(days=index + 1),
|
|
session_id="origin-session",
|
|
task_id="origin-task",
|
|
store=store,
|
|
)
|
|
|
|
emitted = process_due_stability_jobs(
|
|
store=WisdomStore(store.root), at=start + timedelta(days=10)
|
|
)
|
|
|
|
assert len(emitted) == 1
|
|
event = store.local_events(kind="wisdom.candidate")[0]
|
|
assert event["session_id"] == "origin-session"
|
|
assert event["task_id"] == "origin-task"
|
|
assert process_due_stability_jobs(store=store, at=start + timedelta(days=11)) == []
|
|
|
|
|
|
def test_due_stability_waits_for_use_within_the_qualification_window(
|
|
monkeypatch, tmp_path: Path
|
|
):
|
|
skill = _skill(tmp_path)
|
|
_eligible(monkeypatch, skill)
|
|
store = _configured_store(tmp_path)
|
|
start = datetime(2026, 8, 1, tzinfo=timezone.utc)
|
|
record_mutation("learned-skill", at=start, store=store)
|
|
for index in range(3):
|
|
refs = skill / "refs"
|
|
refs.mkdir(exist_ok=True)
|
|
(refs / f"late-use-{index}.md").write_text(str(index), encoding="utf-8")
|
|
record_mutation(
|
|
"learned-skill", at=start + timedelta(days=index + 1), store=store
|
|
)
|
|
|
|
assert process_due_stability_jobs(store=store, at=start + timedelta(days=10)) == []
|
|
assert len(store.due_stability_jobs((start + timedelta(days=10)).isoformat())) == 1
|
|
|
|
event_id = record_successful_use(
|
|
"learned-skill", at=start + timedelta(days=11), store=store
|
|
)
|
|
assert event_id
|
|
assert store.local_events(kind="wisdom.candidate")[0]["qualification"] == (
|
|
"refinement"
|
|
)
|
|
|
|
|
|
def test_ambiguous_classifier_receives_only_a_bounded_before_after_diff(
|
|
monkeypatch,
|
|
):
|
|
captured = {}
|
|
auxiliary = types.ModuleType("agent.auxiliary_client")
|
|
|
|
def call_llm(**kwargs):
|
|
captured.update(kwargs)
|
|
return {"content": "meaningful"}
|
|
|
|
auxiliary.call_llm = call_llm
|
|
auxiliary.extract_content_or_reasoning = lambda response: response["content"]
|
|
monkeypatch.setitem(sys.modules, "agent.auxiliary_client", auxiliary)
|
|
|
|
assert (
|
|
_classify_ambiguous(
|
|
"# Procedure\nUse the old endpoint.\n",
|
|
"# Procedure\nUse the new endpoint and verify the receipt.\n",
|
|
{"added": [], "removed": [], "changed": ["SKILL.md"]},
|
|
)
|
|
== "meaningful"
|
|
)
|
|
payload = json.loads(captured["messages"][1]["content"])
|
|
semantic = payload["untrusted_semantic_diff"]
|
|
assert "Use the old endpoint" in semantic
|
|
assert "Use the new endpoint" in semantic
|
|
assert "usage" not in payload
|
|
assert len(semantic) <= 16000
|
|
|
|
|
|
def test_ambiguous_classifier_failure_is_conservative(monkeypatch, tmp_path: Path):
|
|
skill = _skill(tmp_path)
|
|
_eligible(monkeypatch, skill)
|
|
store = _configured_store(tmp_path)
|
|
now = datetime(2026, 8, 1, tzinfo=timezone.utc)
|
|
record_successful_use("learned-skill", at=now, store=store)
|
|
(skill / "SKILL.md").write_text(
|
|
"---\nname: learned-skill\n---\n# Typo only\n", encoding="utf-8"
|
|
)
|
|
monkeypatch.setattr(
|
|
"hermes_wisdom.qualification._classify_ambiguous",
|
|
lambda *_args: "non_meaningful",
|
|
)
|
|
record_mutation("learned-skill", at=now + timedelta(days=1), store=store)
|
|
with store.transaction() as db:
|
|
row = db.execute("SELECT classification FROM refinement").fetchone()
|
|
assert row[0] == "non_meaningful"
|
|
assert store.due_stability_jobs((now + timedelta(days=30)).isoformat()) == []
|
|
|
|
|
|
def test_dismissal_suppresses_exact_content_but_stronger_path_can_resuggest(
|
|
tmp_path: Path,
|
|
):
|
|
store = _configured_store(tmp_path)
|
|
skill = _skill(tmp_path)
|
|
skill_id = store.register_skill(
|
|
skill, content_hash="sha256:one", source_kind="local"
|
|
)
|
|
first = _emit_candidate(
|
|
store,
|
|
skill_id=skill_id,
|
|
skill_name="learned-skill",
|
|
content_hash="sha256:one",
|
|
qualification="refinement",
|
|
local_reasons={},
|
|
session_id=None,
|
|
task_id=None,
|
|
)
|
|
stronger = _emit_candidate(
|
|
store,
|
|
skill_id=skill_id,
|
|
skill_name="learned-skill",
|
|
content_hash="sha256:one",
|
|
qualification="high_usage",
|
|
local_reasons={},
|
|
session_id=None,
|
|
task_id=None,
|
|
)
|
|
assert first and stronger
|
|
store.dismiss_candidate(skill_id, "sha256:one")
|
|
assert store.local_events(kind="wisdom.candidate") == []
|
|
assert (
|
|
_emit_candidate(
|
|
store,
|
|
skill_id=skill_id,
|
|
skill_name="learned-skill",
|
|
content_hash="sha256:one",
|
|
qualification="high_usage",
|
|
local_reasons={},
|
|
session_id=None,
|
|
task_id=None,
|
|
)
|
|
is None
|
|
)
|
|
assert _emit_candidate(
|
|
store,
|
|
skill_id=skill_id,
|
|
skill_name="learned-skill",
|
|
content_hash="sha256:two",
|
|
qualification="high_usage",
|
|
local_reasons={},
|
|
session_id=None,
|
|
task_id=None,
|
|
)
|
|
|
|
|
|
def test_qualification_entry_points_do_no_local_work_without_entitlement(monkeypatch, tmp_path: Path):
|
|
skill = _skill(tmp_path)
|
|
_eligible(monkeypatch, skill)
|
|
store = _configured_store(tmp_path)
|
|
from tests.wisdom.local_auth import authorize_local
|
|
|
|
authorize_local(monkeypatch, "org-1", expires_in=-1)
|
|
|
|
assert record_successful_use("learned-skill", store=store) is None
|
|
record_mutation("learned-skill", store=store)
|
|
|
|
with store.transaction() as db:
|
|
assert db.execute("SELECT COUNT(*) FROM local_skill").fetchone()[0] == 0
|
|
|
|
|
|
def test_async_qualification_does_not_spawn_threads_without_entitlement(monkeypatch):
|
|
from hermes_wisdom import qualification
|
|
from tests.wisdom.local_auth import authorize_local
|
|
|
|
authorize_local(monkeypatch, "org-1", scopes=[])
|
|
monkeypatch.setattr(
|
|
qualification.threading,
|
|
"Thread",
|
|
lambda **_kwargs: (_ for _ in ()).throw(AssertionError("must not spawn")),
|
|
)
|
|
|
|
qualification.record_successful_use_async("skill")
|
|
qualification.record_mutation_async("skill")
|