11import { expect , it } from "vitest" ;
2- import { validSessionCommand } from "./session-commands.mjs" ;
2+ import { validChannelCommand } from "./session-commands.mjs" ;
33const id = "11111111-1111-4111-8111-111111111111" ;
44const event = ( body , tags = [ [ "h" , id ] ] ) => ( {
55 kind : 9050 ,
@@ -8,11 +8,11 @@ const event = (body, tags = [["h", id]]) => ({
88 tags,
99} ) ;
1010it ( "rejects custom session commands" , ( ) => {
11- expect ( validSessionCommand ( event ( { action : "create" , title : "Work" } ) ) ) . toBe (
11+ expect ( validChannelCommand ( event ( { action : "create" , title : "Work" } ) ) ) . toBe (
1212 false ,
1313 ) ;
1414 expect (
15- validSessionCommand (
15+ validChannelCommand (
1616 event ( { action : "move" , parent_id : id , confirm_history : true } ) ,
1717 ) ,
1818 ) . toBe ( false ) ;
@@ -27,17 +27,17 @@ it("allows only ordinary invitations, without extra roles", () => {
2727 [ "p" , "a" . repeat ( 64 ) ] ,
2828 ] ,
2929 } ;
30- expect ( validSessionCommand ( invite ) ) . toBe ( true ) ;
30+ expect ( validChannelCommand ( invite ) ) . toBe ( true ) ;
3131 expect (
32- validSessionCommand ( {
32+ validChannelCommand ( {
3333 ...invite ,
3434 tags : [ ...invite . tags , [ "role" , "admin" ] ] ,
3535 } ) ,
3636 ) . toBe ( false ) ;
37- expect ( validSessionCommand ( { ...invite , kind : 9001 } ) ) . toBe ( false ) ;
37+ expect ( validChannelCommand ( { ...invite , kind : 9001 } ) ) . toBe ( false ) ;
3838} ) ;
3939
40- it ( "allows only private stream creation marked for Sessions " , ( ) => {
40+ it ( "preserves strict Sessions metadata while allowing ordinary stream visibility " , ( ) => {
4141 const create = {
4242 kind : 9007 ,
4343 created_at : 1 ,
@@ -50,31 +50,29 @@ it("allows only private stream creation marked for Sessions", () => {
5050 [ "about" , "Buzz session (buzz.sessions/v1)" ] ,
5151 ] ,
5252 } ;
53- expect ( validSessionCommand ( create ) ) . toBe ( true ) ;
53+ expect ( validChannelCommand ( create ) ) . toBe ( true ) ;
5454 const child = ( description ) => ( {
5555 ...create ,
5656 tags : create . tags . map ( ( tag ) =>
5757 tag [ 0 ] === "about" ? [ "about" , description ] : tag ,
5858 ) ,
5959 } ) ;
6060 expect (
61- validSessionCommand ( child ( `Buzz session (buzz.sessions/v1)\nparent:${ id } ` ) ) ,
61+ validChannelCommand ( child ( `Buzz session (buzz.sessions/v1)\nparent:${ id } ` ) ) ,
6262 ) . toBe ( true ) ;
6363 for ( const parent of [ "invalid" , `${ id } \nrole:owner` , `${ id } extra` ] ) {
6464 expect (
65- validSessionCommand (
65+ validChannelCommand (
6666 child ( `Buzz session (buzz.sessions/v1)\nparent:${ parent } ` ) ,
6767 ) ,
6868 ) . toBe ( false ) ;
6969 }
7070 for ( const [ index , value ] of [
71- [ 2 , "open" ] ,
7271 [ 3 , "dm" ] ,
73- [ 4 , "arbitrary" ] ,
7472 [ 1 , " " ] ,
7573 ] ) {
7674 expect (
77- validSessionCommand ( {
75+ validChannelCommand ( {
7876 ...create ,
7977 tags : create . tags . map ( ( tag , i ) =>
8078 i === index ? [ tag [ 0 ] , value ] : tag ,
@@ -83,25 +81,123 @@ it("allows only private stream creation marked for Sessions", () => {
8381 ) . toBe ( false ) ;
8482 }
8583 expect (
86- validSessionCommand ( {
84+ validChannelCommand ( {
85+ ...create ,
86+ tags : create . tags . map ( ( tag , i ) =>
87+ i === 4 ? [ tag [ 0 ] , "Buzz session (forged)" ] : tag ,
88+ ) ,
89+ } ) ,
90+ ) . toBe ( false ) ;
91+ expect (
92+ validChannelCommand ( {
8793 ...create ,
8894 tags : [ ...create . tags , [ "p" , "a" . repeat ( 64 ) ] ] ,
8995 } ) ,
9096 ) . toBe ( false ) ;
91- expect ( validSessionCommand ( { ...create , content : "extra" } ) ) . toBe ( false ) ;
97+ expect ( validChannelCommand ( { ...create , content : "extra" } ) ) . toBe ( false ) ;
9298} ) ;
9399
94100it ( "accepts one trailing outbox identifier for invitations and rejects ambiguous envelopes" , ( ) => {
95101 const invite = ( tags ) => ( { kind : 9000 , created_at : 1 , content : "" , tags } ) ;
96102 const h = [ "h" , id ] ,
97103 p = [ "p" , "a" . repeat ( 64 ) ] ,
98104 client = [ "client-id" , id ] ;
99- expect ( validSessionCommand ( invite ( [ h , p , client ] ) ) ) . toBe ( true ) ;
105+ expect ( validChannelCommand ( invite ( [ h , p , client ] ) ) ) . toBe ( true ) ;
100106 for ( const tags of [
101107 [ h , p , client , client ] ,
102108 [ client , h , p ] ,
103109 [ h , p , [ "client-id" , "invalid" ] ] ,
104110 [ h , p , [ ...client , "extra" ] ] ,
105111 ] )
106- expect ( validSessionCommand ( invite ( tags ) ) ) . toBe ( false ) ;
112+ expect ( validChannelCommand ( invite ( tags ) ) ) . toBe ( false ) ;
113+ } ) ;
114+
115+ it ( "allows bounded ordinary stream creation without a Sessions marker" , ( ) => {
116+ const create = {
117+ kind : 9007 ,
118+ created_at : 1 ,
119+ content : "" ,
120+ tags : [
121+ [ "h" , id ] ,
122+ [ "name" , "Release notes" ] ,
123+ [ "visibility" , "open" ] ,
124+ [ "channel_type" , "stream" ] ,
125+ [ "about" , "Updates for the team" ] ,
126+ ] ,
127+ } ;
128+ expect ( validChannelCommand ( create ) ) . toBe ( true ) ;
129+ expect (
130+ validChannelCommand ( { ...create , tags : create . tags . slice ( 0 , 4 ) } ) ,
131+ ) . toBe ( true ) ;
132+ expect (
133+ validChannelCommand ( {
134+ ...create ,
135+ tags : create . tags . map ( ( tag ) =>
136+ tag [ 0 ] === "about" ? [ "about" , "x" . repeat ( 1001 ) ] : tag ,
137+ ) ,
138+ } ) ,
139+ ) . toBe ( false ) ;
140+ expect (
141+ validChannelCommand ( {
142+ ...create ,
143+ tags : create . tags . map ( ( tag ) =>
144+ tag [ 0 ] === "about" ? [ "about" , "Buzz session (forged)" ] : tag ,
145+ ) ,
146+ } ) ,
147+ ) . toBe ( false ) ;
148+ expect (
149+ validChannelCommand ( {
150+ ...create ,
151+ tags : [ ...create . tags , [ "ttl" , "604800" ] ] ,
152+ } ) ,
153+ ) . toBe ( true ) ;
154+ expect (
155+ validChannelCommand ( {
156+ ...create ,
157+ tags : [ ...create . tags . slice ( 0 , 4 ) , [ "ttl" , "604800" ] ] ,
158+ } ) ,
159+ ) . toBe ( true ) ;
160+ for ( const ttl of [ "0" , "-1" , "forever" , "2147483648" ] ) {
161+ expect (
162+ validChannelCommand ( {
163+ ...create ,
164+ tags : [ ...create . tags , [ "ttl" , ttl ] ] ,
165+ } ) ,
166+ ) . toBe ( false ) ;
167+ }
168+ } ) ;
169+
170+ it ( "rejects every truncated mandatory creation-tag prefix" , ( ) => {
171+ const create = {
172+ kind : 9007 ,
173+ created_at : 1 ,
174+ content : "" ,
175+ tags : [
176+ [ "h" , id ] ,
177+ [ "name" , "Release notes" ] ,
178+ [ "visibility" , "open" ] ,
179+ [ "channel_type" , "stream" ] ,
180+ ] ,
181+ } ;
182+ for ( let length = 0 ; length < create . tags . length ; length ++ )
183+ expect (
184+ validChannelCommand ( { ...create , tags : create . tags . slice ( 0 , length ) } ) ,
185+ ) . toBe ( false ) ;
186+ } ) ;
187+
188+ it ( "does not add temporary cleanup to Sessions metadata" , ( ) => {
189+ const create = {
190+ kind : 9007 ,
191+ created_at : 1 ,
192+ content : "" ,
193+ tags : [
194+ [ "h" , id ] ,
195+ [ "name" , "Work" ] ,
196+ [ "visibility" , "private" ] ,
197+ [ "channel_type" , "stream" ] ,
198+ [ "about" , "Buzz session (buzz.sessions/v1)" ] ,
199+ [ "ttl" , "604800" ] ,
200+ ] ,
201+ } ;
202+ expect ( validChannelCommand ( create ) ) . toBe ( false ) ;
107203} ) ;
0 commit comments