fix: align lineloss default periods with page semantics
Default month/week deterministic lineloss requests to the source page's built-in time ranges while preserving explicit-period parsing and existing routing contracts. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -2,6 +2,7 @@ mod common;
|
||||
|
||||
use std::path::PathBuf;
|
||||
|
||||
use chrono::{Datelike, Local};
|
||||
use zeroclaw::skills::load_skills_from_directory;
|
||||
|
||||
use sgclaw::compat::deterministic_submit::{
|
||||
@@ -14,6 +15,24 @@ use sgclaw::compat::tq_lineloss::{
|
||||
};
|
||||
use sgclaw::runtime::is_zhihu_hotlist_task;
|
||||
|
||||
fn expected_default_month() -> String {
|
||||
let today = Local::now().date_naive();
|
||||
let (year, month) = if today.month() == 1 {
|
||||
(today.year() - 1, 12)
|
||||
} else {
|
||||
(today.year(), today.month() - 1)
|
||||
};
|
||||
format!("{year}-{month:02}")
|
||||
}
|
||||
|
||||
fn expected_default_week_range() -> (String, String, String) {
|
||||
let today = Local::now().date_naive();
|
||||
let month_start = today.with_day(1).expect("current month should have day 1");
|
||||
let start = month_start.format("%Y-%m-%d").to_string();
|
||||
let end = today.format("%Y-%m-%d").to_string();
|
||||
(format!("{start}至{end}"), start, end)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn deterministic_submit_discovers_tq_lineloss_skill_contract() {
|
||||
let skills_root = PathBuf::from("D:/data/ideaSpace/rust/sgClaw/claw/claw/skills/skill_staging/skills");
|
||||
@@ -225,6 +244,43 @@ fn lineloss_period_resolver_parses_week_text() {
|
||||
assert_eq!(resolved.payload["weekEfdate"], "2026-03-22");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lineloss_period_resolver_defaults_month_period_from_page_semantics() {
|
||||
let expected_month = expected_default_month();
|
||||
|
||||
assert_eq!(
|
||||
resolve_period("兰州公司 月累计").unwrap(),
|
||||
ResolvedPeriod {
|
||||
mode: PeriodMode::Month,
|
||||
mode_code: "1".to_string(),
|
||||
value: expected_month.clone(),
|
||||
payload: serde_json::json!({
|
||||
"fdate": expected_month,
|
||||
}),
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lineloss_period_resolver_defaults_week_period_from_page_semantics() {
|
||||
let (expected_value, expected_start, expected_end) = expected_default_week_range();
|
||||
|
||||
assert_eq!(
|
||||
resolve_period("兰州公司 周累计").unwrap(),
|
||||
ResolvedPeriod {
|
||||
mode: PeriodMode::Week,
|
||||
mode_code: "2".to_string(),
|
||||
value: expected_value,
|
||||
payload: serde_json::json!({
|
||||
"tjzq": "week",
|
||||
"level": "00",
|
||||
"weekSfdate": expected_start,
|
||||
"weekEfdate": expected_end,
|
||||
}),
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lineloss_period_resolver_prompts_for_missing_year_on_week() {
|
||||
let summary = resolve_period("周累计 第12周")
|
||||
@@ -279,14 +335,35 @@ fn deterministic_lineloss_execution_plan_contains_canonical_args() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn deterministic_lineloss_missing_period_does_not_reach_execution_plan() {
|
||||
fn deterministic_lineloss_missing_period_uses_default_month_execution_plan() {
|
||||
let expected_month = expected_default_month();
|
||||
let decision = decide_deterministic_submit("兰州公司 月累计。。。", None, None);
|
||||
|
||||
match decision {
|
||||
DeterministicSubmitDecision::Prompt { summary } => {
|
||||
assert!(summary.contains("周期") || summary.contains("时间") || summary.contains("2026-03"));
|
||||
DeterministicSubmitDecision::Execute(plan) => {
|
||||
assert_eq!(plan.period_mode, "month");
|
||||
assert_eq!(plan.period_mode_code, "1");
|
||||
assert_eq!(plan.period_value, expected_month);
|
||||
assert!(plan.period_payload.contains("fdate"));
|
||||
}
|
||||
other => panic!("expected missing-period prompt before execution, got {other:?}"),
|
||||
other => panic!("expected missing month period to default into execution, got {other:?}"),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn deterministic_lineloss_missing_period_uses_default_week_execution_plan() {
|
||||
let (expected_value, expected_start, expected_end) = expected_default_week_range();
|
||||
let decision = decide_deterministic_submit("兰州公司 周累计。。。", None, None);
|
||||
|
||||
match decision {
|
||||
DeterministicSubmitDecision::Execute(plan) => {
|
||||
assert_eq!(plan.period_mode, "week");
|
||||
assert_eq!(plan.period_mode_code, "2");
|
||||
assert_eq!(plan.period_value, expected_value);
|
||||
assert!(plan.period_payload.contains(&expected_start));
|
||||
assert!(plan.period_payload.contains(&expected_end));
|
||||
}
|
||||
other => panic!("expected missing week period to default into execution, got {other:?}"),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user