@@ -505,6 +505,7 @@ it("imports a shared agent as a new identity with its name and picture, adopting
505505it ( "delivers mentions and matching watches once, and never the agent's own events" , async ( ) => {
506506 const { service, run, emit } = await setup ( ) ;
507507 await service . create ( { type : "example/echo" , name : "Echo" } ) ;
508+ await service . save ( bot , { attentionEnabled : true } ) ;
508509 const mention = event ( "m" , {
509510 tags : [
510511 [ "h" , channel ] ,
@@ -637,6 +638,7 @@ it("keeps handed-off activity local, without publishing working reactions", asyn
637638it ( "wakes on a reply in a thread it started only by a mention or a watch" , async ( ) => {
638639 const { service, run, emit } = await setup ( ) ;
639640 await service . create ( { type : "example/echo" , name : "Echo" } ) ;
641+ await service . save ( bot , { attentionEnabled : true } ) ;
640642 run . mockImplementationOnce ( async ( { agent } ) => {
641643 await agent . publish ( { kind : 9 , content : "hi" , tags : [ [ "h" , channel ] ] } ) ;
642644 } ) ;
@@ -1305,6 +1307,7 @@ it("fires a due timer once, then again an interval after it ran", async () => {
13051307 vi . useFakeTimers ( { now : 1_000_000 } ) ;
13061308 const { service, run, storage } = await setup ( ) ;
13071309 await service . create ( { type : "example/echo" , name : "Echo" } ) ;
1310+ await service . save ( bot , { attentionEnabled : true } ) ;
13081311 await service . save ( bot , {
13091312 attention : {
13101313 "watch/tick" : {
@@ -1364,6 +1367,7 @@ it("keeps at most one occurrence of a timer waiting, and never runs one removed
13641367 vi . useFakeTimers ( { now : 1_000_000 } ) ;
13651368 const { service, run } = await setup ( ) ;
13661369 await service . create ( { type : "example/echo" , name : "Echo" } ) ;
1370+ await service . save ( bot , { attentionEnabled : true } ) ;
13671371 const timer = ( prompt : string ) =>
13681372 ( {
13691373 type : "timer" ,
@@ -1400,6 +1404,7 @@ it("gives each due timer a turn when one's runs outlast its interval", async ()
14001404 vi . useFakeTimers ( { now : 1_000_000 } ) ;
14011405 const { service, run } = await setup ( ) ;
14021406 await service . create ( { type : "example/echo" , name : "Echo" } ) ;
1407+ await service . save ( bot , { attentionEnabled : true } ) ;
14031408 const timer = ( prompt : string ) =>
14041409 ( {
14051410 type : "timer" ,
@@ -1434,6 +1439,7 @@ it("runs waiting events before a due timer, so a busy timer cannot starve them",
14341439 vi . useFakeTimers ( { now : 1_000_000 } ) ;
14351440 const { service, run, emit } = await setup ( ) ;
14361441 await service . create ( { type : "example/echo" , name : "Echo" } ) ;
1442+ await service . save ( bot , { attentionEnabled : true } ) ;
14371443 await service . save ( bot , {
14381444 attention : {
14391445 "watch/tick" : {
@@ -1548,6 +1554,7 @@ it("keeps the cleanup for later when the session closes while archive state is r
15481554it ( "runs once per matching watch, and passes a classifier watch it cannot classify" , async ( ) => {
15491555 const { service, run, emit } = await setup ( ) ;
15501556 await service . create ( { type : "example/echo" , name : "Echo" } ) ;
1557+ await service . save ( bot , { attentionEnabled : true } ) ;
15511558 await service . save ( bot , {
15521559 attention : {
15531560 "watch/classified" : {
@@ -1587,6 +1594,7 @@ it("runs once per matching watch, and passes a classifier watch it cannot classi
15871594it ( "keeps DMs and reactions to its own messages away from watches" , async ( ) => {
15881595 const { service, run, emit } = await setup ( ) ;
15891596 await service . create ( { type : "example/echo" , name : "Echo" } ) ;
1597+ await service . save ( bot , { attentionEnabled : true } ) ;
15901598 await service . save ( bot , {
15911599 attention : {
15921600 "watch/everything" : {
@@ -1625,6 +1633,7 @@ it("keeps DMs and reactions to its own messages away from watches", async () =>
16251633it ( "wakes a watch only for channels the agent is in, even when it watches all" , async ( ) => {
16261634 const { service, run, emit } = await setup ( ) ;
16271635 await service . create ( { type : "example/echo" , name : "Echo" } ) ;
1636+ await service . save ( bot , { attentionEnabled : true } ) ;
16281637 await service . save ( bot , {
16291638 attention : {
16301639 "watch/everything" : {
@@ -1655,9 +1664,29 @@ it("wakes a watch only for channels the agent is in, even when it watches all",
16551664 } ) ;
16561665} ) ;
16571666
1667+ it ( "keeps a new agent's attention off until its owner turns it on" , async ( ) => {
1668+ const { service, run, emit } = await setup ( ) ;
1669+ await service . create ( { type : "example/echo" , name : "Echo" } ) ;
1670+ expect ( service . find ( bot ) ?. attentionEnabled ) . toBe ( false ) ;
1671+ // Its type's default watch matches, but wakes nothing while off.
1672+ emit ( { events : [ event ( "one" , { content : "deploy" } ) ] } ) ;
1673+ await settle ( ) ;
1674+ await settle ( ) ;
1675+ expect ( run ) . not . toHaveBeenCalled ( ) ;
1676+ await service . save ( bot , { attentionEnabled : true } ) ;
1677+ expect ( service . find ( bot ) ?. attentionEnabled ) . toBe ( true ) ;
1678+ emit ( { events : [ event ( "two" , { content : "deploy" } ) ] } ) ;
1679+ await vi . waitFor ( ( ) => expect ( run ) . toHaveBeenCalledTimes ( 1 ) ) ;
1680+ expect ( run . mock . calls [ 0 ] ?. [ 0 ] . trigger ) . toMatchObject ( {
1681+ type : "watch" ,
1682+ event : { id : "two" . padEnd ( 64 , "0" ) } ,
1683+ } ) ;
1684+ } ) ;
1685+
16581686it ( "drops a queued watch run whose watch was disabled, or whose attention went off, before it ran" , async ( ) => {
16591687 const { service, run, emit } = await setup ( ) ;
16601688 await service . create ( { type : "example/echo" , name : "Echo" } ) ;
1689+ await service . save ( bot , { attentionEnabled : true } ) ;
16611690 let release = ( ) => { } ;
16621691 run . mockImplementationOnce (
16631692 ( ) => new Promise < void > ( ( resolve ) => ( release = resolve ) ) ,
@@ -1699,6 +1728,7 @@ it("drops a queued watch run whose watch was disabled, or whose attention went o
16991728it ( "drops a queued watch run when attention goes off and on, or its watch is replaced, before it ran" , async ( ) => {
17001729 const { service, run, emit } = await setup ( ) ;
17011730 await service . create ( { type : "example/echo" , name : "Echo" } ) ;
1731+ await service . save ( bot , { attentionEnabled : true } ) ;
17021732 const watch = service . find ( bot ) ?. attention [ "watch/channel" ] ?. value ;
17031733 let release = ( ) => { } ;
17041734 const hold = ( ) =>
@@ -1743,6 +1773,7 @@ it("drops a queued watch run when attention goes off and on, or its watch is rep
17431773it ( "tells a run whose type queued its work whether that work is still current" , async ( ) => {
17441774 const { service, run, emit } = await setup ( ) ;
17451775 await service . create ( { type : "example/echo" , name : "Echo" } ) ;
1776+ await service . save ( bot , { attentionEnabled : true } ) ;
17461777 const watch = service . find ( bot ) ?. attention [ "watch/channel" ] ?. value ;
17471778 emit ( { events : [ event ( "one" , { content : "deploy" } ) ] } ) ;
17481779 await vi . waitFor ( ( ) => expect ( run ) . toHaveBeenCalledTimes ( 1 ) ) ;
@@ -1773,6 +1804,7 @@ it("voids a handed-off timer occurrence once attention or the timer is reset", a
17731804 vi . useFakeTimers ( { now : 1_000_000 } ) ;
17741805 const { service, run } = await setup ( ) ;
17751806 await service . create ( { type : "example/echo" , name : "Echo" } ) ;
1807+ await service . save ( bot , { attentionEnabled : true } ) ;
17761808 const timer = {
17771809 type : "timer" ,
17781810 interest_id : "default" ,
@@ -1813,6 +1845,7 @@ it("runs a spent timer again when its owner restarts it", async () => {
18131845 vi . useFakeTimers ( { now : 1_000_000 } ) ;
18141846 const { service, run } = await setup ( ) ;
18151847 await service . create ( { type : "example/echo" , name : "Echo" } ) ;
1848+ await service . save ( bot , { attentionEnabled : true } ) ;
18161849 const once = {
18171850 type : "timer" ,
18181851 interest_id : "default" ,
@@ -2561,6 +2594,7 @@ async function handleOf(
25612594it ( "lets a run read and write its attention with expected-state tokens" , async ( ) => {
25622595 const { service, run, emit } = await setup ( ) ;
25632596 await service . create ( { type : "example/echo" , name : "Echo" } ) ;
2597+ await service . save ( bot , { attentionEnabled : true } ) ;
25642598 const { attention } = await handleOf ( run , emit ) ;
25652599 expect ( attention . enabled ( ) ) . toBe ( true ) ;
25662600 expect ( attention . classifier ( ) ) . toBe ( "unavailable" ) ;
0 commit comments