1717 * knowledge page has exactly one sidebar entry exactly when the hub lists it.
1818 */
1919
20+ import { createHash } from 'node:crypto' ;
2021import { describe , it , expect , vi , afterEach } from 'vitest' ;
2122import { LiteKernel } from '@objectstack/core' ;
2223import type { Plugin , PluginContext } from '@objectstack/core' ;
@@ -37,6 +38,7 @@ import {
3738 aiEmbedderSettingsSpecifiers ,
3839 aiTestEmbedderActionHandler ,
3940 knowledgeTestActionHandler ,
41+ type CryptoAdapter ,
4042 type SettingsService ,
4143} from '@objectstack/service-settings' ;
4244import { KnowledgeServicePlugin } from '../knowledge-service-plugin.js' ;
@@ -215,6 +217,24 @@ const API_KEY = 'sk-embedder-secret-37094';
215217
216218interface LoggedLine { level : string ; line : string }
217219
220+ /**
221+ * The API key is a secret field, which the settings service stores only through
222+ * an adapter that declares confidentiality; this kernel has no data engine, so
223+ * the adapter (not a crypto provider) is the seam.
224+ */
225+ class ConfidentialTestAdapter implements CryptoAdapter {
226+ readonly confidential = true ;
227+ async encrypt ( plaintext : string ) : Promise < string > {
228+ return 'kms:' + Buffer . from ( plaintext , 'utf8' ) . toString ( 'base64' ) ;
229+ }
230+ async decrypt ( ciphertext : string ) : Promise < string > {
231+ return Buffer . from ( ciphertext . replace ( / ^ k m s : / , '' ) , 'base64' ) . toString ( 'utf8' ) ;
232+ }
233+ digest ( plaintext : string ) : string {
234+ return createHash ( 'sha256' ) . update ( plaintext ) . digest ( 'hex' ) ;
235+ }
236+ }
237+
218238/** Records every line the kernel's shared logger is handed. */
219239class LogRecorder implements Plugin {
220240 name = 'test.log-recorder' ;
@@ -320,7 +340,7 @@ async function bootEmbedder(opts: {
320340 enableEventSync : false ,
321341 sources : [ { id : 'docs' , label : 'Docs' , adapter : 'vec' , source : { kind : 'http' , urls : [ 'https://docs.example.com/' ] } } ] ,
322342 } ) ) ;
323- kernel . use ( new SettingsServicePlugin ( { env : { } , registerRoutes : false } ) ) ;
343+ kernel . use ( new SettingsServicePlugin ( { env : { } , registerRoutes : false , crypto : new ConfidentialTestAdapter ( ) } ) ) ;
324344 kernel . use ( new EmbeddingAdapterPlugin ( ) ) ;
325345 if ( opts . saved ) kernel . use ( new SavedAiSettings ( opts . saved ) ) ;
326346 await kernel . bootstrap ( ) ;
0 commit comments