battery-device-bts/src/test/java/com/battery/device/bts/NewareBtsAdapterContractTest.java
@@ -86,7 +86,7 @@
    @Test
    void watermarkIsTheLastPersistedRowAndSamplesAreStrictlyAfterIt()
    {
        ScriptedPipe pipe = new ScriptedPipe().rows(1, 5);
        ScriptedPipe pipe = new ScriptedPipe().rows(1, 5).on("inquire", CAPABLE_CLIENT);
        try (TestDataObservationAdapter adapter = (TestDataObservationAdapter) adapter(pipe))
        {
            SampleWatermark watermark = adapter.currentWatermark(CHANNEL);
@@ -94,7 +94,8 @@
            // 水位 = 已落盘行数那一行本身;行数就是最后一行的 seqid(实测一致)。
            assertEquals(5L, watermark.sequenceId());
            assertEquals(rowTime(5), watermark.deviceTime());
            assertEquals(List.of("inquiredf", "download:5:1"), pipe.commands());
            // 先探测一次客户端能力(inquire 带 cycle_id → 支持数据文件命令),再取水位。
            assertEquals(List.of("inquire", "inquiredf", "download:5:1"), pipe.commands());
            pipe.reset();
            var rows = adapter.samplesSince(CHANNEL, new SampleWatermark(rowTime(3), 3L));
@@ -120,10 +121,10 @@
    }
    @Test
    void treatsAClientWithoutInquiredfAsNotRowBasedInsteadOfFailing()
    void treatsAnInquiredfReplyWithoutARecordAsNotRowBased()
    {
        // 实测 7.6.0.1475 不支持 inquiredf(应答里没有 chl 记录)。这不是失败,是该构建的真实能力。
        ScriptedPipe pipe = new ScriptedPipe().on("inquiredf",
        // 应答里没有 chl 记录(命令看似支持却没有该通道的数据)→ 不按数据行接收,回落轮询槽位。
        ScriptedPipe pipe = new ScriptedPipe().on("inquire", CAPABLE_CLIENT).on("inquiredf",
                "<bts><cmd>inquiredf_resp</cmd><list count=\"0\" /></bts>");
        try (TestDataObservationAdapter adapter = (TestDataObservationAdapter) adapter(pipe))
        {
@@ -132,9 +133,32 @@
    }
    @Test
    void doesNotSendDataFileCommandsToAClientWithoutCycleId()
    {
        // 实测 7.6.0.1475:`inquire` 应答不带 cycle_id,而它没有 inquiredf/download/downloadStepLayer。
        // 向它发 inquiredf 的代价不只是超时——实测会让该接口的 `inquire` 连续 8 分钟无应答
        // (getdevinfo 仍正常),等于干扰了那台上位机的对外接口。所以一条都不发。
        ScriptedPipe pipe = new ScriptedPipe().on("inquire", "<bts><cmd>inquire_resp</cmd><list count=\"1\">"
                + "<inquire dev=\"21-103-1-1-0\" step_id=\"5\" step_type=\"rest\" workstatus=\"working\""
                + " voltage=\"1.2531\" current=\"0.0000\" auxtemp=\"0\" auxvol=\"0\" /></list></bts>");
        try (TestDataObservationAdapter adapter = (TestDataObservationAdapter) adapter(pipe))
        {
            assertNull(adapter.currentWatermark(CHANNEL));
            assertTrue(adapter.stepRecords(CHANNEL).isEmpty());
            assertTrue(adapter.cycleRecords(CHANNEL).isEmpty());
            assertFalse(pipe.commands().contains("inquiredf"));
            assertFalse(pipe.commands().contains("download"));
            assertFalse(pipe.commands().contains("downloadsteplayer"));
            // 探测只做一次,之后一直按"不支持"处理。
            assertEquals(List.of("inquire"), pipe.commands());
        }
    }
    @Test
    void aChannelWithNoTestHasAZeroWatermarkAndNoSamples()
    {
        ScriptedPipe pipe = new ScriptedPipe().on("inquiredf",
        ScriptedPipe pipe = new ScriptedPipe().on("inquire", CAPABLE_CLIENT).on("inquiredf",
                "<bts><cmd>inquiredf_resp</cmd><list count=\"1\"><chl devtype=\"25\" devid=\"81\" subdevid=\"1\""
                        + " chlid=\"2\" testid=\"316\" count=\"0\">true</chl></list></bts>");
        try (TestDataObservationAdapter adapter = (TestDataObservationAdapter) adapter(pipe))
@@ -243,17 +267,22 @@
    @Test
    void aChannelWithNoTestInTheBufferHasNoStepsOrCycles()
    {
        ScriptedPipe pipe = new ScriptedPipe()
        ScriptedPipe pipe = new ScriptedPipe().on("inquire", CAPABLE_CLIENT)
                .on("downloadStepLayer", "<bts><cmd>downloadStepLayer_resp</cmd><list count=\"0\" /></bts>");
        try (TestDataObservationAdapter adapter = (TestDataObservationAdapter) adapter(pipe))
        {
            assertTrue(adapter.stepRecords(CHANNEL).isEmpty());
            assertTrue(adapter.cycleRecords(CHANNEL).isEmpty());
            // 缓冲里没有测试就直接是空,不必再去问工作状态。
            assertEquals(List.of("downloadsteplayer"), pipe.commands());
            assertEquals(List.of("inquire", "downloadsteplayer"), pipe.commands());
        }
    }
    /** 一个"支持数据文件命令"的客户端应答(8.0 系:`inquire` 带 `cycle_id`)。 */
    private static final String CAPABLE_CLIENT = "<bts><cmd>inquire_resp</cmd><list count=\"1\">"
            + "<inquire dev=\"25-81-1-2-0\" cycle_id=\"1\" step_id=\"5\" step_type=\"rest\""
            + " workstatus=\"working\" voltage=\"1.25\" /></list></bts>";
    @Test
    void aFailedStateReadSkipsTheRoundInsteadOfHandingOutTheRunningStep()
    {