feat(设备日志/后台配置/密钥检测): 补齐已上线未提交的设备日志与app_config,并合入检测模型解耦
三部分均已部署到双节点(当前线上 JAR 009efc3e),本次补齐仓库状态,避免"已上线未提交" 在后续最小构建比对里被误判。 - 设备日志管理:modules/devicelog + DeviceLogOssProperties(主机B 独立 MinIO,仅内网) + V127 device_log_file/device_log_config + admin-vue 日志管理页;客户端/麦象按 offset 增量上报(X-Internal-Token),查询仅超管 - 后台通用配置:modules/appconfig + V128 app_config 键值表;工作台「开店流程」密码改服务端 校验(POST /api/kd-flow/verify),改密码只需 UPDATE 该行、客户端无需重新发版 - 密钥检测模型解耦:新增 aiimage.user-secret.check-model(env AIIMAGE_USER_SECRET_CHECK_MODEL), 默认 doubao-seed-2-0-lite-260215 —— 同系列 mini 在中继分组下无可用渠道(503 model_not_found), 实测 lite 可路由;UserSecretModule 去掉 LlmTarget 改 resolveLlmHost,探测日志带 model= - 前端:密钥面板「检测配置密钥」按钮不再折行;client-changelog 补 4.0.19/4.0.20/4.0.21 条目 注:application.yml 与 PropertiesConfig 同时承载上述多个部分,故未按功能拆分提交
This commit is contained in:
+69
@@ -0,0 +1,69 @@
|
||||
package com.nanri.aiimage.modules.appconfig.service;
|
||||
|
||||
import com.nanri.aiimage.modules.appconfig.mapper.AppConfigMapper;
|
||||
import com.nanri.aiimage.modules.appconfig.model.entity.AppConfigEntity;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* 开店流程访问密码服务端校验单测。
|
||||
*
|
||||
* <p>重点覆盖"宁可锁死也不放行":配置缺失/为空一律判失败,避免 app_config 还没落库时
|
||||
* 出现"空密码即可通过"。
|
||||
*/
|
||||
class KdFlowServiceTest {
|
||||
|
||||
private final AppConfigMapper mapper = mock(AppConfigMapper.class);
|
||||
|
||||
private KdFlowService serviceWith(String configured) {
|
||||
when(mapper.selectOne(any())).thenReturn(row(configured));
|
||||
return new KdFlowService(mapper);
|
||||
}
|
||||
|
||||
private static AppConfigEntity row(String value) {
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
AppConfigEntity e = new AppConfigEntity();
|
||||
e.setConfigKey(KdFlowService.PASSWORD_KEY);
|
||||
e.setConfigValue(value);
|
||||
return e;
|
||||
}
|
||||
|
||||
@Test
|
||||
void 密码正确时通过() {
|
||||
assertThat(serviceWith("hjx6688").matches("hjx6688")).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
void 密码错误时不通过() {
|
||||
assertThat(serviceWith("hjx6688").matches("hjx6699")).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
void 输入首尾空格按去掉后比对() {
|
||||
assertThat(serviceWith("hjx6688").matches(" hjx6688 ")).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
void 输入为空或null时不通过() {
|
||||
KdFlowService s = serviceWith("hjx6688");
|
||||
assertThat(s.matches(null)).isFalse();
|
||||
assertThat(s.matches("")).isFalse();
|
||||
assertThat(s.matches(" ")).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
void 服务端未配置该键时一律不通过() {
|
||||
assertThat(serviceWith(null).matches("hjx6688")).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
void 服务端配置为空串时一律不通过() {
|
||||
assertThat(serviceWith("").matches("")).isFalse();
|
||||
}
|
||||
}
|
||||
+187
@@ -0,0 +1,187 @@
|
||||
package com.nanri.aiimage.modules.devicelog.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.MybatisConfiguration;
|
||||
import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
|
||||
import com.nanri.aiimage.common.exception.BusinessException;
|
||||
import com.nanri.aiimage.common.mapper.AdminUserMapper;
|
||||
import com.nanri.aiimage.config.DeviceLogOssProperties;
|
||||
import com.nanri.aiimage.modules.devicelog.mapper.DeviceLogFileMapper;
|
||||
import com.nanri.aiimage.modules.devicelog.model.entity.DeviceLogFileEntity;
|
||||
import com.nanri.aiimage.modules.devicelog.model.vo.DeviceLogContentVo;
|
||||
import com.nanri.aiimage.modules.devicelog.storage.DeviceLogStorageService;
|
||||
import org.apache.ibatis.builder.MapperBuilderAssistant;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.contains;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.ArgumentMatchers.isNull;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
class DeviceLogServiceTest {
|
||||
|
||||
private static final LocalDate LOG_DATE = LocalDate.of(2026, 9, 15);
|
||||
|
||||
/** 单测无 Spring 上下文,需手动注册实体 TableInfo 供 LambdaWrapper 解析列名。 */
|
||||
@BeforeAll
|
||||
static void initTableInfo() {
|
||||
TableInfoHelper.initTableInfo(new MapperBuilderAssistant(new MybatisConfiguration(), ""),
|
||||
DeviceLogFileEntity.class);
|
||||
}
|
||||
|
||||
private final DeviceLogFileMapper mapper = mock(DeviceLogFileMapper.class);
|
||||
private final AdminUserMapper adminUserMapper = mock(AdminUserMapper.class);
|
||||
private final DeviceLogStorageService storage = mock(DeviceLogStorageService.class);
|
||||
private final DeviceLogOssProperties properties = new DeviceLogOssProperties();
|
||||
|
||||
private DeviceLogService service() {
|
||||
properties.setRetentionDays(7);
|
||||
when(storage.enabled()).thenReturn(true);
|
||||
return new DeviceLogService(mapper, adminUserMapper, storage, properties);
|
||||
}
|
||||
|
||||
private static DeviceLogFileEntity row(long uploadedBytes, int parts) {
|
||||
DeviceLogFileEntity row = new DeviceLogFileEntity();
|
||||
row.setId(1L);
|
||||
row.setSource("client");
|
||||
row.setDeviceId("dev-1");
|
||||
row.setFileName("2026_09_15.log");
|
||||
row.setLogDate(LOG_DATE);
|
||||
row.setUploadedBytes(uploadedBytes);
|
||||
row.setPartCount(parts);
|
||||
return row;
|
||||
}
|
||||
|
||||
private static byte[] gzip(String text) throws Exception {
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
try (GZIPOutputStream gz = new GZIPOutputStream(out)) {
|
||||
gz.write(text.getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
return out.toByteArray();
|
||||
}
|
||||
|
||||
@Test
|
||||
void firstPartAppendsAndAdvances() throws Exception {
|
||||
when(mapper.selectOne(any())).thenReturn(row(0L, 0));
|
||||
when(mapper.update(isNull(), any())).thenReturn(1);
|
||||
byte[] payload = gzip("line-1\n");
|
||||
|
||||
DeviceLogService.PartResult result = service().recordPart("client", "dev-1", "PC-A", 7L,
|
||||
"2026_09_15.log", LOG_DATE, 0L, 7L, payload);
|
||||
|
||||
assertThat(result.accepted()).isTrue();
|
||||
assertThat(result.skipped()).isFalse();
|
||||
assertThat(result.uploadedBytes()).isEqualTo(7L);
|
||||
assertThat(result.partCount()).isEqualTo(1);
|
||||
verify(storage).putPart(
|
||||
contains("device-logs/client/dev-1/2026-09-15/2026_09_15.log/000000000000.log.gz"),
|
||||
eq(payload));
|
||||
}
|
||||
|
||||
@Test
|
||||
void duplicateOffsetIsIdempotentlySkipped() throws Exception {
|
||||
when(mapper.selectOne(any())).thenReturn(row(500L, 3));
|
||||
|
||||
DeviceLogService.PartResult result = service().recordPart("client", "dev-1", null, null,
|
||||
"2026_09_15.log", LOG_DATE, 100L, 7L, gzip("old\n"));
|
||||
|
||||
assertThat(result.accepted()).isFalse();
|
||||
assertThat(result.skipped()).isTrue();
|
||||
assertThat(result.uploadedBytes()).isEqualTo(500L);
|
||||
verify(storage, never()).putPart(any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void gapOffsetIsRejectedWith409() throws Exception {
|
||||
when(mapper.selectOne(any())).thenReturn(row(100L, 1));
|
||||
|
||||
assertThatThrownBy(() -> service().recordPart("client", "dev-1", null, null,
|
||||
"2026_09_15.log", LOG_DATE, 500L, 7L, gzip("jump\n")))
|
||||
.isInstanceOfSatisfying(BusinessException.class, ex -> {
|
||||
assertThat(ex.getCode()).isEqualTo(409);
|
||||
assertThat(ex.getMessage()).contains("偏移不连续");
|
||||
});
|
||||
verify(storage, never()).putPart(any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void firstUploadRegistersRow() throws Exception {
|
||||
when(mapper.selectOne(any())).thenReturn(null);
|
||||
when(mapper.insert(any(DeviceLogFileEntity.class))).thenReturn(1);
|
||||
when(mapper.update(isNull(), any())).thenReturn(1);
|
||||
|
||||
service().recordPart("maixiang", "host-9", "host-9", null,
|
||||
"kk-browser.log", LOG_DATE, 0L, 10L, gzip("boot\n"));
|
||||
|
||||
ArgumentCaptor<DeviceLogFileEntity> captor = ArgumentCaptor.forClass(DeviceLogFileEntity.class);
|
||||
verify(mapper).insert(captor.capture());
|
||||
DeviceLogFileEntity inserted = captor.getValue();
|
||||
assertThat(inserted.getSource()).isEqualTo("maixiang");
|
||||
assertThat(inserted.getDeviceId()).isEqualTo("host-9");
|
||||
assertThat(inserted.getFileName()).isEqualTo("kk-browser.log");
|
||||
assertThat(inserted.getLogDate()).isEqualTo(LOG_DATE);
|
||||
assertThat(inserted.getUploadedBytes()).isZero();
|
||||
assertThat(inserted.getPartCount()).isZero();
|
||||
}
|
||||
|
||||
@Test
|
||||
void rejectsInvalidSource() throws Exception {
|
||||
assertThatThrownBy(() -> service().recordPart("BAD SOURCE!", "dev-1", null, null,
|
||||
"a.log", LOG_DATE, 0L, 10L, gzip("x\n")))
|
||||
.isInstanceOf(BusinessException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void rejectsOversizedPart() throws Exception {
|
||||
assertThatThrownBy(() -> service().recordPart("client", "dev-1", null, null,
|
||||
"a.log", LOG_DATE, 0L, 100L * 1024 * 1024, gzip("x\n")))
|
||||
.isInstanceOf(BusinessException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void readTailMergesPartsAndTrimsToLineBoundary() throws Exception {
|
||||
String partA = "A".repeat(10000) + "\n";
|
||||
String partB = "B".repeat(10000) + "\n";
|
||||
when(mapper.selectById(1L)).thenReturn(row(partA.length() + partB.length(), 2));
|
||||
when(storage.listParts(any())).thenReturn(List.of(
|
||||
"device-logs/client/dev-1/2026-09-15/2026_09_15.log/000000000000.log.gz",
|
||||
"device-logs/client/dev-1/2026-09-15/2026_09_15.log/000000000010001.log.gz"));
|
||||
when(storage.readPartBytes(contains("000000000000"))).thenReturn(gzip(partA));
|
||||
when(storage.readPartBytes(contains("000000010001"))).thenReturn(gzip(partB));
|
||||
|
||||
DeviceLogContentVo vo = service().readTail(1L, 16L * 1024L);
|
||||
|
||||
// 两段合计超过 16KB:裁到最近行边界,只留较新的 B 段,且不留半行
|
||||
assertThat(vo.getContent()).isEqualTo(partB);
|
||||
assertThat(vo.getShownBytes()).isEqualTo(partB.length());
|
||||
assertThat(vo.isTruncated()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
void readTailReturnsWholeContentWhenUnderLimit() throws Exception {
|
||||
when(mapper.selectById(1L)).thenReturn(row(10L, 2));
|
||||
when(storage.listParts(any())).thenReturn(List.of(
|
||||
"device-logs/client/dev-1/2026-09-15/2026_09_15.log/000000000000.log.gz",
|
||||
"device-logs/client/dev-1/2026-09-15/2026_09_15.log/000000000005.log.gz"));
|
||||
when(storage.readPartBytes(contains("000000000000"))).thenReturn(gzip("AAAA\n"));
|
||||
when(storage.readPartBytes(contains("000000000005"))).thenReturn(gzip("BBBB\n"));
|
||||
|
||||
DeviceLogContentVo vo = service().readTail(1L, 16L * 1024L);
|
||||
|
||||
assertThat(vo.getContent()).isEqualTo("AAAA\nBBBB\n");
|
||||
assertThat(vo.isTruncated()).isFalse();
|
||||
}
|
||||
}
|
||||
+3
-1
@@ -16,6 +16,7 @@ class UserApiSecretCheckServiceTest {
|
||||
private final UserApiSecretCheckService service = new UserApiSecretCheckService(
|
||||
new AppearancePatentProperties(),
|
||||
new SimilarAsinProperties(),
|
||||
new com.nanri.aiimage.config.UserSecretProperties(),
|
||||
mock(JikipProxyClient.class),
|
||||
new ObjectMapper());
|
||||
|
||||
@@ -72,7 +73,8 @@ class UserApiSecretCheckServiceTest {
|
||||
void probeFailsWithInsufficientBalanceWhenProviderOverdrawn() {
|
||||
JikipProxyClient jikip = mock(JikipProxyClient.class);
|
||||
UserApiSecretCheckService probeService = new UserApiSecretCheckService(
|
||||
new AppearancePatentProperties(), new SimilarAsinProperties(), jikip, new ObjectMapper());
|
||||
new AppearancePatentProperties(), new SimilarAsinProperties(),
|
||||
new com.nanri.aiimage.config.UserSecretProperties(), jikip, new ObjectMapper());
|
||||
when(jikip.isExtractConfigured()).thenReturn(true);
|
||||
when(jikip.fetchProxyUrl()).thenThrow(new JikipProxyClient.InsufficientBalanceException());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user